来自静态属性的内爆数组?

时间:2016-12-06 15:18:16

标签: php arrays properties static refactoring

我有一个有两个静态属性的类。

$statuses是一个数组,其状态ID及其字符串值可供显示。

$status_changes是当前状态ID的数组,值是允许状态更改的数组。

class Status {
    public static $statuses = [
        1 => 'Box Stock',
        11 => 'Box Stock (Refurbished)',
        2 => 'Transit',
        3 => 'Active',
        4 => 'Inactive',
        12 => 'RMA Authorized',
        5 => 'RMA',
        6 => 'Scrap',
        8 => 'Customer Spare',
        9 => 'Consigned',
        13 => 'Holding',
        10 => 'Internal Use',
        7 => 'Unknown'
    ];

    public static $status_changes = [
        1 => [2, 3, 10, 13],
        11 => [2, 10, 13],
        2 => [3, 10, 12, 13],
        3 => [4],
        4 => [3, 6, 7, 11, 12],
        12 => [5, 6, 11],
        5 => [6, 11],
        6 => [7],
        8 => [3],
        9 => [3, 8],
        13 => [3, 8],
        10 => [3, 6, 11],
        7 => [6, 11]
    ];

    function echoAllowed($status) {
        echo implode(', ', array_map(function ($s) { 
            return Status::$statuses[$s]; 
        },
        self::$status_changes[$status]));
    }
}

$s = new Status();
$s->echoAllowed(1);
// Should print "Transit, Active, Internal Use, Holding".

在给定状态ID的情况下,破坏允许状态更改列表的最佳方法是什么? (正如我在echoAllowed()方法中所做的那样。)

0 个答案:

没有答案