1 | <?php |
||
17 | class Extractor |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Max number of rows to parse |
||
22 | */ |
||
23 | const MAX_LINES = 5000; |
||
24 | |||
25 | /** |
||
26 | * Max columns in a single line to parse |
||
27 | */ |
||
28 | const MAX_COLS = 500; |
||
29 | |||
30 | /** |
||
31 | * Pattern to extract hook arguments |
||
32 | */ |
||
33 | const PATTERN_HOOK = '/->attach\(\s*(.+?)\s*\)/s'; |
||
34 | |||
35 | /** |
||
36 | * Pattern to extract method names |
||
37 | */ |
||
38 | const PATTERN_FUNCTION = '/function +(\w+)\s*\(/'; |
||
39 | |||
40 | /** |
||
41 | * Pattern to extract class namespaces |
||
42 | */ |
||
43 | const PATTERN_NAMESPACE = '/^namespace +(.+?)\s*;/'; |
||
44 | |||
45 | /** |
||
46 | * Pattern to extract class names |
||
47 | */ |
||
48 | const PATTERN_CLASS = '/(?:^abstract +|^)class +(.+?)(\s+|\n\r|$)/'; |
||
49 | |||
50 | /** |
||
51 | * The current method while parsing hooks |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $current_function; |
||
55 | |||
56 | /** |
||
57 | * The current class name space while parsing hooks |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $current_namespace; |
||
61 | |||
62 | /** |
||
63 | * The current class while parsing hooks |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $current_class; |
||
67 | |||
68 | /** |
||
69 | * Returns an array of hook scopes/types |
||
70 | * @return array |
||
71 | */ |
||
72 | public function getHookScopes() |
||
78 | |||
79 | /** |
||
80 | * Prepares extracted hook data |
||
81 | * @param array $data |
||
82 | * @return array |
||
83 | */ |
||
84 | public function prepareHook(array $data) |
||
108 | |||
109 | /** |
||
110 | * Returns an array of prepared hook arguments |
||
111 | * @param array $arguments |
||
112 | * @param array $data |
||
113 | * @return array |
||
114 | */ |
||
115 | protected function prepareHookArguments(array $arguments, array $data) |
||
133 | |||
134 | /** |
||
135 | * Returns an array of extracted hooks |
||
136 | * @param array $options |
||
137 | * @return array |
||
138 | */ |
||
139 | public function getHooks(array $options) |
||
180 | |||
181 | /** |
||
182 | * Whether a given hook name is in array of scopes |
||
183 | * @param string $hook |
||
184 | * @param array $scopes |
||
185 | * @return boolean |
||
186 | */ |
||
187 | protected function inScope($hook, array $scopes) |
||
197 | |||
198 | /** |
||
199 | * Returns an array of extracted hooks from a single file |
||
200 | * @param string $file |
||
201 | * @return array |
||
202 | * @throws RuntimeException |
||
203 | */ |
||
204 | public function parse($file) |
||
263 | |||
264 | /** |
||
265 | * Returns an array of scanned files to extract hooks from or counts extracted items |
||
266 | * @param string $directory |
||
267 | * @param bool $count |
||
268 | * @return integer|array |
||
269 | */ |
||
270 | public function scan($directory, $count = false) |
||
283 | |||
284 | } |
||
285 |