1 | <?php |
||
16 | class Factory { |
||
17 | /** |
||
18 | * Create a new condition |
||
19 | * |
||
20 | * @param string|array|Closure $options |
||
21 | * @return ConditionInterface |
||
22 | */ |
||
23 | 12 | public static function make( $options ) { |
|
38 | |||
39 | /** |
||
40 | * Check if the passed argument is a registered condition type |
||
41 | * |
||
42 | * @param mixed $condition_type |
||
43 | * @return boolean |
||
44 | */ |
||
45 | 6 | protected static function conditionTypeRegistered( $condition_type ) { |
|
46 | 6 | if ( ! is_string( $condition_type ) ) { |
|
47 | 1 | return false; |
|
48 | } |
||
49 | |||
50 | 5 | $condition_class = Framework::resolve( 'framework.routing.conditions.' . $condition_type ); |
|
51 | 5 | return ( $condition_class !== null ); |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Resolve the condition type and it's arguments from an options array |
||
56 | * |
||
57 | * @param array $options |
||
58 | * @return array |
||
59 | */ |
||
60 | 6 | protected static function getConditionTypeAndArguments( $options ) { |
|
61 | 6 | $type = $options[0]; |
|
62 | 6 | $arguments = array_slice( $options, 1 ); |
|
63 | |||
64 | 6 | if ( ! static::conditionTypeRegistered( $type ) ) { |
|
65 | 3 | if ( is_callable( $type ) ) { |
|
66 | 2 | $type = 'custom'; |
|
67 | 2 | $arguments = $options; |
|
68 | 2 | } else { |
|
69 | 1 | throw new Exception( 'Unknown condition type specified: ' . $type ); |
|
70 | } |
||
71 | 2 | } |
|
72 | |||
73 | return array( |
||
74 | 5 | 'type' => $type, |
|
75 | 5 | 'arguments' => $arguments, |
|
76 | 5 | ); |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * Create a new condition from a url |
||
81 | * |
||
82 | * @param string $url |
||
83 | * @return ConditionInterface |
||
84 | */ |
||
85 | 1 | protected static function makeFromUrl( $url ) { |
|
88 | |||
89 | /** |
||
90 | * Create a new condition from an array of conditions |
||
91 | * |
||
92 | * @param array $options |
||
93 | * @return ConditionInterface |
||
94 | */ |
||
95 | 1 | protected static function makeFromArrayOfConditions( $options ) { |
|
98 | |||
99 | /** |
||
100 | * Create a new condition from an array |
||
101 | * |
||
102 | * @param array $options |
||
103 | * @return ConditionInterface |
||
104 | */ |
||
105 | 8 | protected static function makeFromArray( $options ) { |
|
121 | |||
122 | /** |
||
123 | * Create a new condition from a closure |
||
124 | * |
||
125 | * @param Closure $closure |
||
126 | * @return ConditionInterface |
||
127 | */ |
||
128 | 1 | protected static function makeFromClosure( Closure $closure ) { |
|
131 | } |
||
132 |