src/Observers/ObserverVisitor.php
/**
     * Prepare the observers defined in the system configuration.
     *
     * @param \TechDivision\Import\Subjects\SubjectInterface $subject   The subject to prepare the observers for
     * @param array                                          $observers The array with the observers
     * @param string                                         $type      The actual observer type
     *
     * @return void
     */
Prepare the observers defined in the system configuration.
@param \TechDivision\Import\Subjects\SubjectInterface $subject   The subject to prepare the observers for
@param array                                          $observers The array with the observers
@param string                                         $type      The actual observer type

@return void
Prepare the observers defined in the system configuration . @param \ TechDivision \ Import \ Subjects \ SubjectInterface $subject The subject to prepare the observers for @param array $observers The array with the observers @param string $type The actual observer type @return void
protected function prepareObservers(SubjectInterface $subject, array $observers, $type = null)
    {
        foreach ($observers as $key => $observer) {
            if ($type == null) {
                $type = $key;
            }
            if (is_array($observer)) {
                $this->prepareObservers($subject, $observer, $type);
            } else {
                $instance = $this->container->get($observer);
                if ($instance instanceof ObserverFactoryInterface) {
                    $observ = $instance->createObserver($subject);
                    $observ->setSubject($subject);
                    $subject->registerObserver($observ, $type);
                } elseif ($instance instanceof ObserverInterface) {
                    $subject->registerObserver($instance, $type);
                } else {
                    throw new \InvalidArgumentException(
                        sprintf(
                            'Instance of "%s" doesn\'t implement interface "%s" or "%s"',
                            $observer,
                            ObserverFactoryInterface::class,
                            ObserverInterface::class
                        )
                    );
                }
            }
        }
    }
protected function prepareObservers ( SubjectInterface $ subject , array $ observers , $ type = null ) { foreach ( $ observers as $ key => $ observer ) { if ( $ type == null ) { $ type = $ key ; } if ( is_array ( $ observer ) ) { $ this -> prepareObservers ( $ subject , $ observer , $ type ) ; } else { $ instance = $ this -> container -> get ( $ observer ) ; if ( $ instance instanceof ObserverFactoryInterface ) { $ observ = $ instance -> createObserver ( $ subject ) ; $ observ -> setSubject ( $ subject ) ; $ subject -> registerObserver ( $ observ , $ type ) ; } elseif ( $ instance instanceof ObserverInterface ) { $ subject -> registerObserver ( $ instance , $ type ) ; } else { throw new \ InvalidArgumentException ( sprintf ( 'Instance of "%s" doesn\'t implement interface "%s" or "%s"' , $ observer , ObserverFactoryInterface :: class , ObserverInterface :: class ) ) ; } } } }
Prepare the observers defined in the system configuration.
Prepare the observers defined in the system configuration .
// iterate over the array with observers and prepare them // we have to initialize the type only on the first level // query whether or not we've an subarry or not // create the instance of the observer/factory // query whether or not a factory has been specified