/**
  * {@inheritdoc}
  */
 public function getConnectionAdapter(Host $host)
 {
     if (isset($this->connectionAdapters[$host->getConnectionType()])) {
         $connectionIdentifier = spl_object_hash($host);
         if (isset($this->connections[$connectionIdentifier]) === false) {
             $connectionAdapterArguments = $host->getConnectionOptions();
             $connectionAdapterArguments['hostname'] = $host->getHostname();
             $this->connections[$connectionIdentifier] = ObjectFactory::getInstance()->newInstance($this->connectionAdapters[$host->getConnectionType()], $connectionAdapterArguments);
         }
         return $this->connections[$connectionIdentifier];
     }
 }
Ejemplo n.º 2
0
 /**
  * Initializes the event listeners and subscribers configured in the configuration.
  */
 public function initializeEventListeners()
 {
     $configuration = $this->getConfiguration();
     $eventDispatcher = $this->getContainer()->get('event_dispatcher');
     foreach ($configuration->getEventListeners() as $eventName => $listeners) {
         foreach ($listeners as $listener) {
             list($listenerClassName, $listenerMethodName) = explode('::', $listener);
             $listenerInstance = ObjectFactory::getInstance()->newInstance($listenerClassName);
             if ($listenerInstance !== null) {
                 $eventDispatcher->addListener($eventName, array($listenerInstance, $listenerMethodName));
             }
         }
     }
     foreach ($configuration->getEventSubscribers() as $subscriber) {
         $subscriberInstance = ObjectFactory::getInstance()->newInstance($subscriber['class'], $subscriber);
         if ($subscriberInstance instanceof EventSubscriberInterface) {
             $eventDispatcher->addSubscriber($subscriberInstance);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Returns the configured hosts.
  *
  * @return Host[]
  */
 public function getHosts()
 {
     if (empty($this->hosts) && isset($this->configuration['hosts'])) {
         foreach ($this->configuration['hosts'] as $host) {
             $this->hosts[] = ObjectFactory::getInstance()->newInstance(Host::class, $host);
         }
     }
     return $this->hosts;
 }
Ejemplo n.º 4
0
 /**
  * testNewInstanceSetsSecondArgumentWithNullValue
  *
  * Tests if ObjectFactory::newInstance sets the second argument with a null value
  *
  * @access public
  * @return null
  **/
 public function testNewInstanceSetsSecondArgumentWithNullValue()
 {
     $argumentValue = 'test';
     $secondArgumentValue = null;
     $thirdArgumentValue = 'test3';
     $objectFactory = ObjectFactory::getInstance();
     $instance = $objectFactory->newInstance('Nijens\\Utilities\\Tests\\MockObjectMultipleArguments', array('argument' => $argumentValue, 'secondArgument' => $secondArgumentValue, 'thirdArgument' => $thirdArgumentValue));
     $this->assertSame($argumentValue, $instance->argument);
     $this->assertSame($secondArgumentValue, $instance->secondArgument);
     $this->assertSame($thirdArgumentValue, $instance->thirdArgument);
 }