1: | <?php |
2: | |
3: | namespace Teto\Object; |
4: | |
5: | use function call_user_func; |
6: | use function in_array; |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | trait MethodAlias |
16: | { |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | public function __call($name, array $args) |
26: | { |
27: | if (!isset(self::$method_aliases)) { |
28: | throw new \LogicException(static::class . '::$method_aliases is not set.'); |
29: | } |
30: | |
31: | if (isset(self::$method_aliases[$name])) { |
32: | $method = self::$method_aliases[$name]; |
33: | } elseif (in_array($name, self::$method_aliases)) { |
34: | $method = $name; |
35: | } else { |
36: | throw new \BadMethodCallException(static::class . "::{$name}() is not exists."); |
37: | } |
38: | |
39: | return call_user_func([$this, $method]); |
40: | } |
41: | } |
42: | |