Total Complexity | 8 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Coverage | 56.52% |
Changes | 0 |
1 | <?php |
||
5 | trait LazyLoad |
||
6 | { |
||
7 | protected $lazyProperties = []; |
||
8 | 6 | public function lazyProperty(string $property, callable $resolve) |
|
9 | { |
||
10 | 6 | unset($this->{$property}); |
|
11 | 6 | $this->lazyProperties[$property] = [ 'loaded' => false, 'value' => null, 'resolve' => $resolve ]; |
|
12 | 6 | return $this; |
|
13 | } |
||
14 | public function overrideLazyProperty(string $property, $value) |
||
15 | { |
||
16 | if (!isset($this->lazyProperties[$property])) { |
||
17 | return $this; |
||
18 | } |
||
19 | $this->lazyProperties[$property]['value'] = $value; |
||
20 | $this->lazyProperties[$property]['loaded'] = true; |
||
21 | $this->{$property} = $this->lazyProperties[$property]['value']; |
||
22 | return $this; |
||
23 | } |
||
24 | 2 | public function loadLazyProperty(string $property) |
|
35 | } |
||
36 | 2 | public function __get($property) |
|
37 | { |
||
42 | } |
||
43 | } |