1 <?php
2
3 /*
4 * This file is part of the ICanBoogie package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace ICanBoogie\Prototype;
13
14 class Hooks
15 {
16 /**
17 * Synthesizes the "prototypes" config from the "hooks" config.
18 *
19 * @param array $fragments
20 *
21 * @return array[string]callable
22 *
23 * @throws \InvalidArgumentException if a method definition is missing the '::' separator.
24 */
25 static public function synthesize_config(array $fragments)
26 {
27 $methods = [];
28
29 foreach ($fragments as $pathname => $fragment)
30 {
31 if (empty($fragment['prototypes']))
32 {
33 continue;
34 }
35
36 foreach ($fragment['prototypes'] as $method => $callback)
37 {
38 if (strpos($method, '::') === false)
39 {
40 throw new \InvalidArgumentException(sprintf
41 (
42 'Invalid method name "%s", must be <code>class_name::method_name</code> in "%s"', $method, $pathname
43 ));
44 }
45
46 list($class, $method) = explode('::', $method);
47
48 $methods[$class][$method] = $callback;
49 }
50 }
51
52 return $methods;
53 }
54 }