Example #1
0
 /**
  * Initializes components.
  *
  * @param \Es\Services\ServicesInterface $services  The services
  * @param \Es\Events\ListenersInterface  $listeners The listeners
  * @param \Es\Events\EventsInterface     $events    The events
  * @param \Es\System\ConfigInterface     $config    The system configuration
  *
  * @throws \RuntimeException If the components have already been initialized
  */
 public function init(ServicesInterface $services, ListenersInterface $listeners, EventsInterface $events, ConfigInterface $config)
 {
     if ($this->initialized) {
         throw new RuntimeException('The components have already been initialized.');
     }
     $this->initialized = true;
     foreach ($this->container as $component) {
         if (method_exists($component, 'getServicesConfig')) {
             $services->add($component->getServicesConfig());
         }
         if (method_exists($component, 'getListenersConfig')) {
             $listeners->add($component->getListenersConfig());
         }
         if (method_exists($component, 'getEventsConfig')) {
             foreach ($component->getEventsConfig() as $item) {
                 call_user_func_array([$events, 'attach'], $item);
             }
         }
         if (method_exists($component, 'getSystemConfig')) {
             $config->merge($component->getSystemConfig());
         }
     }
 }
Example #2
0
 /**
  * Merges with other listeners.
  *
  * @param ListenersInterface $source The data source
  *
  * @return self
  */
 public function merge(ListenersInterface $source)
 {
     $this->registry = array_merge($this->registry, $source->getRegistry());
     $this->instances = array_merge($this->instances, $source->getInstances());
     return $this;
 }