Ejemplo n.º 1
0
 public function configureServiceManager(ServiceManager $serviceManager)
 {
     $allowOverride = $this->getAllowOverride();
     isset($allowOverride) ? $serviceManager->setAllowOverride($allowOverride) : null;
     foreach ($this->getFactories() as $name => $factory) {
         $serviceManager->setFactory($name, $factory);
     }
     foreach ($this->getAbstractFactories() as $factory) {
         $serviceManager->addAbstractFactory($factory);
     }
     foreach ($this->getInvokables() as $name => $invokable) {
         $serviceManager->setInvokableClass($name, $invokable);
     }
     foreach ($this->getServices() as $name => $service) {
         $serviceManager->setService($name, $service);
     }
     foreach ($this->getAliases() as $alias => $nameOrAlias) {
         $serviceManager->setAlias($alias, $nameOrAlias);
     }
     foreach ($this->getInitializers() as $initializer) {
         $serviceManager->addInitializer($initializer);
     }
     foreach ($this->getShared() as $name => $isShared) {
         $serviceManager->setShared($name, $isShared);
     }
 }
Ejemplo n.º 2
0
    public function configureServiceManager(ServiceManager $serviceManager)
    {
        foreach ($this->getFactories() as $name => $factory) {
            $serviceManager->setFactory($name, $factory);
        }

        foreach ($this->getAbstractFactories() as $factory) {
            $serviceManager->addAbstractFactory($factory);
        }

        foreach ($this->getInvokables() as $name => $invokable) {
            $serviceManager->setInvokableClass($name, $invokable);
        }

        foreach ($this->getServices() as $name => $service) {
            $serviceManager->setService($name, $service);
        }

        foreach ($this->getAliases() as $alias => $nameOrAlias) {
            $serviceManager->setAlias($alias, $nameOrAlias);
        }

        foreach ($this->getShared() as $name => $isShared) {
            $serviceManager->setShared($name, $isShared);
        }
    }
Ejemplo n.º 3
0
 /**
  * Static method for quick and easy initialization of the Console Application.
  *
  * If you use this init() method, you cannot specify a service with the
  * name of 'ApplicationConfig' in your service manager config. This name is
  * reserved to hold the array from application.config.php.
  *
  * The following services can only be overridden from application.config.php:
  *
  * - ModuleManager
  * - SharedEventManager
  * - EventManager & Zend\EventManager\EventManagerInterface
  *
  * All other services are configured after module loading, thus can be
  * overridden by modules.
  *
  * @param array $configuration
  * @return Application
  */
 public static function init($configuration = [])
 {
     $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array();
     $serviceManager = new ServiceManager(new Service\ServiceManagerConfig($smConfig));
     $serviceManager->setService('ApplicationConfig', $configuration);
     $serviceManager->get('ModuleManager')->loadModules();
     $listenersFromAppConfig = isset($configuration['listeners']) ? $configuration['listeners'] : array();
     $config = $serviceManager->get('Config');
     $listenersFromConfigService = isset($config['listeners']) ? $config['listeners'] : array();
     $listeners = array_unique(array_merge($listenersFromConfigService, $listenersFromAppConfig));
     return $serviceManager->get('Application')->bootstrap($listeners);
 }
Ejemplo n.º 4
0
 protected function mockApplication($firewallEnabled = false)
 {
     $serviceManager = new ServiceManager();
     //mock event manager
     $mockEventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface');
     //ensure the event manager "trigger" is executed
     $mockEventManager->expects($this->once())->method('trigger');
     $serviceManager->setService('EventManager', $mockEventManager);
     //mock requests
     $mockRequest = $this->getMock('Zend\\Http\\Request');
     $serviceManager->setService('Request', $mockRequest);
     $mockResponse = $this->getMock('Zend\\Http\\PhpEnvironment\\Response');
     $serviceManager->setService('Response', $mockResponse);
     //mock application
     $mockApplication = $this->getMock('Zend\\Mvc\\Application', [], [[], $serviceManager]);
     $mockApplication->method('getEventManager')->willReturn($mockEventManager);
     $serviceManager->setService('Application', $mockApplication);
 }
Ejemplo n.º 5
0
 /**
  * Register a service with the locator.
  *
  * Validates that the service object via validatePlugin() prior to
  * attempting to register it.
  *
  * @param  string $name
  * @param  mixed $service
  * @param  bool $shared
  * @return AbstractPluginManager
  * @throws Exception\InvalidServiceNameException
  */
 public function setService($name, $service, $shared = true)
 {
     if ($service) {
         $this->validatePlugin($service);
     }
     parent::setService($name, $service, $shared);
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Configure service manager
  *
  * @param ServiceManager $serviceManager
  * @return void
  */
 public function configureServiceManager(ServiceManager $serviceManager)
 {
     if (($allowOverride = $this->getAllowOverride()) !== null) {
         $serviceManager->setAllowOverride($allowOverride);
     }
     foreach ($this->getFactories() as $name => $factory) {
         $serviceManager->setFactory($name, $factory);
     }
     foreach ($this->getAbstractFactories() as $factory) {
         $serviceManager->addAbstractFactory($factory);
     }
     foreach ($this->getInvokables() as $name => $invokable) {
         $serviceManager->setInvokableClass($name, $invokable);
     }
     foreach ($this->getServices() as $name => $service) {
         $serviceManager->setService($name, $service);
     }
     foreach ($this->getAliases() as $alias => $nameOrAlias) {
         $serviceManager->setAlias($alias, $nameOrAlias);
     }
     foreach ($this->getInitializers() as $initializer) {
         $serviceManager->addInitializer($initializer);
     }
     foreach ($this->getShared() as $name => $isShared) {
         $serviceManager->setShared($name, $isShared);
     }
     foreach ($this->getDelegators() as $originalServiceName => $delegators) {
         foreach ($delegators as $delegator) {
             $serviceManager->addDelegator($originalServiceName, $delegator);
         }
     }
 }