| @@ 71-89 (lines=19) @@ | ||
| 68 | * |
|
| 69 | * @return void |
|
| 70 | */ |
|
| 71 | public function prepareCallbacks(SubjectInterface $subject, array $callbacks, $type = null) |
|
| 72 | { |
|
| 73 | ||
| 74 | // iterate over the array with callbacks and prepare them |
|
| 75 | foreach ($callbacks as $key => $callback) { |
|
| 76 | // we have to initialize the type only on the first level |
|
| 77 | if ($type == null) { |
|
| 78 | $type = $key; |
|
| 79 | } |
|
| 80 | ||
| 81 | // query whether or not we've an subarry or not |
|
| 82 | if (is_array($callback)) { |
|
| 83 | $this->prepareCallbacks($subject, $callback, $type); |
|
| 84 | } else { |
|
| 85 | $callbackInstance = $this->callbackFactory($subject, $callback); |
|
| 86 | $subject->registerCallback($callbackInstance, $type); |
|
| 87 | } |
|
| 88 | } |
|
| 89 | } |
|
| 90 | ||
| 91 | /** |
|
| 92 | * Initialize and return a new callback of the passed type. |
|
| @@ 71-89 (lines=19) @@ | ||
| 68 | * |
|
| 69 | * @return void |
|
| 70 | */ |
|
| 71 | protected function prepareObservers(SubjectInterface $subject, array $observers, $type = null) |
|
| 72 | { |
|
| 73 | ||
| 74 | // iterate over the array with observers and prepare them |
|
| 75 | foreach ($observers as $key => $observer) { |
|
| 76 | // we have to initialize the type only on the first level |
|
| 77 | if ($type == null) { |
|
| 78 | $type = $key; |
|
| 79 | } |
|
| 80 | ||
| 81 | // query whether or not we've an subarry or not |
|
| 82 | if (is_array($observer)) { |
|
| 83 | $this->prepareObservers($subject, $observer, $type); |
|
| 84 | } else { |
|
| 85 | $observerInstance = $this->observerFactory($subject, $observer); |
|
| 86 | $subject->registerObserver($observerInstance, $type); |
|
| 87 | } |
|
| 88 | } |
|
| 89 | } |
|
| 90 | ||
| 91 | /** |
|
| 92 | * Initialize and return a new observer of the passed type. |
|