| Total Complexity | 6 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | abstract class Loader implements LoadsProxiedObjects |
||
| 11 | { |
||
| 12 | /** @var ObservesProxyLoading[] */ |
||
| 13 | private $observers = []; |
||
| 14 | |||
| 15 | /** @var mixed|object */ |
||
| 16 | private $forWhom; |
||
| 17 | |||
| 18 | /** @var string */ |
||
| 19 | private $property; |
||
| 20 | |||
| 21 | /** @var string|null */ |
||
| 22 | private $position; |
||
| 23 | |||
| 24 | public function __construct($forWhom, string $property, $position = null) |
||
| 25 | { |
||
| 26 | $this->forWhom = $forWhom; |
||
| 27 | $this->property = $property; |
||
| 28 | $this->position = $position; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function attach(ObservesProxyLoading $observer) : void |
||
| 32 | { |
||
| 33 | $this->observers[] = $observer; |
||
| 34 | } |
||
| 35 | |||
| 36 | public function detach(ObservesProxyLoading $observer) : void |
||
| 37 | { |
||
| 38 | unset($this->observers[array_search($observer, $this->observers, true)]); |
||
| 39 | } |
||
| 40 | |||
| 41 | final public function loadTheInstance() |
||
| 42 | { |
||
| 43 | $instance = $this->doLoad($this->forWhom, $this->property, $this->position); |
||
| 44 | $this->tellThemWeMadeThis($instance); |
||
| 45 | return $instance; |
||
| 46 | } |
||
| 47 | |||
| 48 | protected function tellThemWeMadeThis($instance) |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | protected abstract function doLoad($forWhom, string $property, $position = null); |
||
| 56 | } |
||
| 57 |