1 | <?php |
||
21 | class Helpers |
||
22 | { |
||
23 | static private $mapping = [ |
||
24 | |||
25 | 'contextualize' => [ __CLASS__, 'default_contextualize' ], |
||
26 | 'decontextualize' => [ __CLASS__, 'default_decontextualize' ], |
||
27 | 'absolutize_url' => [ __CLASS__, 'default_absolutize_url' ] |
||
28 | |||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * Calls the callback of a patchable function. |
||
33 | * |
||
34 | * @param string $name Name of the function. |
||
35 | * @param array $arguments Arguments. |
||
36 | * |
||
37 | * @return mixed |
||
38 | */ |
||
39 | static public function __callStatic($name, array $arguments) |
||
43 | |||
44 | /** |
||
45 | * Patches a patchable function. |
||
46 | * |
||
47 | * @param string $name Name of the function. |
||
48 | * @param callable $callback Callback. |
||
49 | * |
||
50 | * @throws \RuntimeException is attempt to patch an undefined function. |
||
51 | */ |
||
52 | // @codeCoverageIgnoreStart |
||
53 | static public function patch($name, $callback) |
||
54 | { |
||
55 | if (empty(self::$mapping[$name])) |
||
56 | { |
||
57 | throw new \RuntimeException("Undefined patchable: $name."); |
||
58 | } |
||
59 | |||
60 | self::$mapping[$name] = $callback; |
||
61 | } |
||
62 | // @codeCoverageIgnoreEnd |
||
63 | |||
64 | /* |
||
65 | * Default implementations |
||
66 | */ |
||
67 | |||
68 | static protected function default_contextualize($pathname) |
||
72 | |||
73 | static protected function default_decontextualize($pathname) |
||
77 | |||
78 | static protected function default_absolutize_url($url) |
||
82 | } |
||
83 |