| @@ 83-116 (lines=34) @@ | ||
| 80 | * |
|
| 81 | * @return void |
|
| 82 | */ |
|
| 83 | protected function prepareCallbacks(SubjectInterface $subject, array $callbacks, $type = null) |
|
| 84 | { |
|
| 85 | ||
| 86 | // iterate over the array with callbacks and prepare them |
|
| 87 | foreach ($callbacks as $key => $callback) { |
|
| 88 | // we have to initialize the type only on the first level |
|
| 89 | if ($type == null) { |
|
| 90 | $type = $key; |
|
| 91 | } |
|
| 92 | ||
| 93 | // query whether or not we've an subarry or not |
|
| 94 | if (is_array($callback)) { |
|
| 95 | $this->prepareCallbacks($subject, $callback, $type); |
|
| 96 | } else { |
|
| 97 | // create the instance of the callback/factory |
|
| 98 | $instance = $this->container->get($callback); |
|
| 99 | // query whether or not a factory has been specified |
|
| 100 | if ($instance instanceof CallbackFactoryInterface) { |
|
| 101 | $subject->registerCallback($instance->createCallback($subject), $type); |
|
| 102 | } elseif ($instance instanceof CallbackInterface) { |
|
| 103 | $subject->registerCallback($instance, $type); |
|
| 104 | } else { |
|
| 105 | throw new \InvalidArgumentException( |
|
| 106 | sprintf( |
|
| 107 | 'Instance of "%s" doesn\'t implement interface "%s" or "%s"', |
|
| 108 | $callback, |
|
| 109 | CallbackFactoryInterface::class, |
|
| 110 | CallbackInterface::class |
|
| 111 | ) |
|
| 112 | ); |
|
| 113 | } |
|
| 114 | } |
|
| 115 | } |
|
| 116 | } |
|
| 117 | } |
|
| 118 | ||
| @@ 83-116 (lines=34) @@ | ||
| 80 | * |
|
| 81 | * @return void |
|
| 82 | */ |
|
| 83 | protected function prepareObservers(SubjectInterface $subject, array $observers, $type = null) |
|
| 84 | { |
|
| 85 | ||
| 86 | // iterate over the array with observers and prepare them |
|
| 87 | foreach ($observers as $key => $observer) { |
|
| 88 | // we have to initialize the type only on the first level |
|
| 89 | if ($type == null) { |
|
| 90 | $type = $key; |
|
| 91 | } |
|
| 92 | ||
| 93 | // query whether or not we've an subarry or not |
|
| 94 | if (is_array($observer)) { |
|
| 95 | $this->prepareObservers($subject, $observer, $type); |
|
| 96 | } else { |
|
| 97 | // create the instance of the observer/factory |
|
| 98 | $instance = $this->container->get($observer); |
|
| 99 | // query whether or not a factory has been specified |
|
| 100 | if ($instance instanceof ObserverFactoryInterface) { |
|
| 101 | $subject->registerObserver($instance->createObserver($subject), $type); |
|
| 102 | } elseif ($instance instanceof ObserverInterface) { |
|
| 103 | $subject->registerObserver($instance, $type); |
|
| 104 | } else { |
|
| 105 | throw new \InvalidArgumentException( |
|
| 106 | sprintf( |
|
| 107 | 'Instance of "%s" doesn\'t implement interface "%s" or "%s"', |
|
| 108 | $observer, |
|
| 109 | ObserverFactoryInterface::class, |
|
| 110 | ObserverInterface::class |
|
| 111 | ) |
|
| 112 | ); |
|
| 113 | } |
|
| 114 | } |
|
| 115 | } |
|
| 116 | } |
|
| 117 | } |
|
| 118 | ||