1 | <?php |
||
7 | class Factory |
||
8 | { |
||
9 | /** |
||
10 | * @var mixed |
||
11 | */ |
||
12 | protected $defaultPolicy; |
||
13 | |||
14 | /** |
||
15 | * Create a new Factory instance. |
||
16 | * |
||
17 | * @param \Closure $defaultPolicy |
||
18 | */ |
||
19 | public function __construct($defaultPolicy = null) |
||
23 | |||
24 | /** |
||
25 | * Make a Policy object. |
||
26 | * |
||
27 | * @param string|array|callable|null $rules |
||
28 | * @return Policy |
||
29 | */ |
||
30 | public static function make($rules) |
||
56 | |||
57 | /** |
||
58 | * Parse a string pattern and get a Policy. |
||
59 | * |
||
60 | * @param string $pattern |
||
61 | * @return Policy |
||
62 | */ |
||
63 | protected function fromPattern($pattern) |
||
69 | |||
70 | /** |
||
71 | * Parse a rules array and get a Policy. |
||
72 | * |
||
73 | * @param array $rules |
||
74 | * @return Policy |
||
75 | */ |
||
76 | protected function fromArray(array $rules) |
||
84 | |||
85 | /** |
||
86 | * Parse string into an array of method names and argument lists. |
||
87 | * |
||
88 | * For example |
||
89 | * "where(id|name, =, *)" |
||
90 | * becomes |
||
91 | * [ |
||
92 | * "where" => ["id|name", "=", "*"] |
||
93 | * ] |
||
94 | * |
||
95 | * @param string $input |
||
96 | * @return array |
||
97 | */ |
||
98 | protected function parseStringToArray($input) |
||
99 | { |
||
100 | return array_build( |
||
|
|||
101 | preg_split('#(?<=\))\s*(?=[a-z])#i', $input), // split on spaces between e.g. `where(*) orderBy(*)` |
||
102 | function($index, $rule) { |
||
103 | |||
104 | if ( ! preg_match('#^(?<method>[a-z]+)\((?<args>[^)]*)\)$#i', $rule, $clause)) { |
||
105 | throw new InvalidArgumentException('Could not parse rule ['.$rule.']'); |
||
106 | } |
||
107 | |||
108 | return [ |
||
109 | $clause['method'], |
||
110 | preg_split('#\s*,\s*#', $clause['args']) |
||
111 | ]; |
||
112 | } |
||
113 | ); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Use a callback to create a Policy. |
||
118 | * |
||
119 | * @param callable $callback |
||
120 | * @return Policy |
||
121 | */ |
||
122 | protected function fromCallback(callable $callback) |
||
130 | |||
131 | /** |
||
132 | * Return the default policy. |
||
133 | * |
||
134 | * @return Policy |
||
135 | */ |
||
136 | protected function fromDefault() |
||
140 | |||
141 | /** |
||
142 | * Create an null Policy. |
||
143 | * |
||
144 | * @return Policy |
||
145 | */ |
||
146 | protected function fromEmpty() |
||
150 | } |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.