1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Latte;
9:
10: use LogicException;
11:
12:
13: 14: 15:
16: trait Strict
17: {
18:
19: 20: 21: 22:
23: public function __call($name, $args)
24: {
25: $class = method_exists($this, $name) ? 'parent' : get_class($this);
26: $items = (new \ReflectionClass($this))->getMethods(\ReflectionMethod::IS_PUBLIC);
27: $hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean $t()?" : '.';
28: throw new LogicException("Call to undefined method $class::$name()$hint");
29: }
30:
31:
32: 33: 34: 35:
36: public static function __callStatic($name, $args)
37: {
38: $rc = new \ReflectionClass(get_called_class());
39: $items = array_intersect($rc->getMethods(\ReflectionMethod::IS_PUBLIC), $rc->getMethods(\ReflectionMethod::IS_STATIC));
40: $hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean $t()?" : '.';
41: throw new LogicException("Call to undefined static method {$rc->getName()}::$name()$hint");
42: }
43:
44:
45: 46: 47: 48:
49: public function &__get($name)
50: {
51: $rc = new \ReflectionClass($this);
52: $items = array_diff($rc->getProperties(\ReflectionProperty::IS_PUBLIC), $rc->getProperties(\ReflectionProperty::IS_STATIC));
53: $hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean $$t?" : '.';
54: throw new LogicException("Attempt to read undeclared property {$rc->getName()}::$$name$hint");
55: }
56:
57:
58: 59: 60: 61:
62: public function __set($name, $value)
63: {
64: $rc = new \ReflectionClass($this);
65: $items = array_diff($rc->getProperties(\ReflectionProperty::IS_PUBLIC), $rc->getProperties(\ReflectionProperty::IS_STATIC));
66: $hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean $$t?" : '.';
67: throw new LogicException("Attempt to write to undeclared property {$rc->getName()}::$$name$hint");
68: }
69:
70:
71: 72: 73:
74: public function __isset($name)
75: {
76: return false;
77: }
78:
79:
80: 81: 82: 83:
84: public function __unset($name)
85: {
86: $class = get_class($this);
87: throw new LogicException("Attempt to unset undeclared property $class::$$name.");
88: }
89: }
90: