1 | <?php |
||
30 | class ScopedPropertyAccess implements PropertyAccess |
||
31 | { |
||
32 | /** @var string */ |
||
33 | private $scopeClass; |
||
34 | /** @var string */ |
||
35 | private $propertyName; |
||
36 | |||
37 | /** @var bool */ |
||
38 | private static $initialized = false; |
||
39 | /** @var \Closure */ |
||
40 | private static $getAccess; |
||
41 | /** @var \Closure */ |
||
42 | private static $setAccess; |
||
43 | |||
44 | /** |
||
45 | * @param string $scopeClass Fqcn of the scope that declares the property |
||
46 | * @param string $propertyName The name of the property |
||
47 | * |
||
48 | * @return ScopedPropertyAccess |
||
49 | */ |
||
50 | 41 | public static function create($scopeClass, $propertyName) |
|
51 | { |
||
52 | 41 | $ret = new self; |
|
53 | 41 | $ret->scopeClass = $scopeClass; |
|
54 | 41 | $ret->propertyName = $propertyName; |
|
55 | |||
56 | // we need to at least initialize this class ones |
||
57 | 41 | if (self::$initialized === false) { |
|
58 | $ret->init(); |
||
59 | } |
||
60 | |||
61 | 41 | return $ret; |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Make use of the static create method |
||
66 | */ |
||
67 | private function __construct() { } |
||
68 | |||
69 | /** |
||
70 | * Called on unserialze |
||
71 | */ |
||
72 | 2 | public function __wakeup() |
|
79 | |||
80 | 1 | private function init() |
|
86 | |||
87 | /** |
||
88 | * Get the value of the property |
||
89 | * |
||
90 | * @param mixed $subject The object to get the value from |
||
91 | * |
||
92 | * @return mixed |
||
93 | */ |
||
94 | 11 | public function get($subject) |
|
100 | |||
101 | /** |
||
102 | * Set the value of the property |
||
103 | * |
||
104 | * @param mixed $subject The object to set the value to |
||
105 | * @param mixed $value |
||
106 | */ |
||
107 | 8 | public function set($subject, $value) |
|
112 | } |
||
113 |