getServiceManager() public method

Retrieve the service manager
public getServiceManager ( ) : Zend\ServiceManager\ServiceManager
return Zend\ServiceManager\ServiceManager
Example #1
0
 public function __construct($name = null, array $data = array(), $dataName = '')
 {
     parent::__construct($name, $data, $dataName);
     $this->app = \Bootstrap::$app;
     $this->sm = $this->app->getServiceManager();
     $this->evm = $this->app->getEventManager();
 }
 /**
  * {@inheritdoc}
  */
 public function initialize(ContextInterface $context)
 {
     if ($context instanceof ApplicationAwareInterface) {
         $context->setApplication($this->application);
     }
     if ($context instanceof ServiceLocatorAwareInterface) {
         $context->setServiceLocator($this->application->getServiceManager());
     }
 }
 /**
  * @BeforeFeature
  */
 public static function clearDatabase()
 {
     $em = self::$zendApp->getServiceManager()->get('doctrine.entitymanager.orm_default');
     $q = $em->createQuery('delete from CargoBackend\\Model\\Cargo\\Cargo');
     $q->execute();
     $q = $em->createQuery('delete from CargoBackend\\Model\\Cargo\\RouteSpecification');
     $q->execute();
     $q = $em->createQuery('delete from CargoBackend\\Model\\Cargo\\Itinerary');
     $q->execute();
 }
 /**
  * @return \Zend\Mvc\Application
  */
 public function getApplication()
 {
     if ($this->spiffyApplication) {
         return $this->spiffyApplication;
     }
     Console::overrideIsConsole($this->getUseConsoleRequest());
     $this->spiffyApplication = SpiffyTest::getInstance()->getApplication();
     $events = $this->spiffyApplication->getEventManager();
     $events->detach($this->spiffyApplication->getServiceManager()->get('SendResponseListener'));
     return $this->spiffyApplication;
 }
 /**
  * @Then I should have the application
  */
 public function applicationExists(TableNode $table)
 {
     /** @var ApplicationManager $applicationManager */
     $applicationManager = self::$application->getServiceManager()->get('application/application-manager');
     $data = [];
     foreach ($table->getTable() as $row) {
         $data[$row[0]] = $row[1];
     }
     $application = $applicationManager->get($data['name']);
     \PHPUnit_Framework_Assert::assertInstanceOf('Continuous\\DeployAgent\\Application\\Application', $application);
     foreach ($data as $property => $value) {
         switch ($property) {
             case 'pipeline':
                 $property = 'reference';
             case 'token':
             case 'repositoryProvider':
             case 'repository':
                 \PHPUnit_Framework_Assert::assertAttributeEquals($value, $property, $application->getProvider());
                 break;
             case 'provider':
                 $provider = self::$application->getServiceManager()->get('provider/' . $value);
                 \PHPUnit_Framework_Assert::assertAttributeInstanceOf(get_class($provider), $property, $application);
                 break;
             default:
                 \PHPUnit_Framework_Assert::assertAttributeEquals($value, $property, $application);
         }
     }
 }
Example #6
0
 /**
  * Adds a value to the ServiceManager to indicate if an exception must be
  * thrown or caught.
  *
  * @param boolean $catch
  * @return null
  */
 protected function setCatchExceptions($catch)
 {
     $serviceManager = $this->application->getServiceManager();
     $serviceManager->setAllowOverride(true);
     $serviceManager->setService('KernelCatchExceptions', $catch);
     $serviceManager->setAllowOverride(false);
 }
 public static function createDatabase(\Zend\Mvc\Application $application)
 {
     // build test database
     $entityManager = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
     $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata());
     // build audit database
     $auditEntityManager = $application->getServiceManager()->get('doctrine.entitymanager.orm_zf_doctrine_audit');
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($auditEntityManager);
     $schemaTool->createSchema($auditEntityManager->getMetadataFactory()->getAllMetadata());
     // Run audit fixtures
     $loader = new ServiceLocatorAwareLoader($application->getServiceManager());
     $purger = new ORMPurger();
     $executor = new ORMExecutor($auditEntityManager, $purger);
     $loader->loadFromDirectory(__DIR__ . '/../src/Fixture');
     $executor->execute($loader->getFixtures(), true);
 }
Example #8
0
 /**
  *
  */
 private function createHelpers()
 {
     /** @var HelperPluginManager $viewPluginManager */
     $viewPluginManager = $this->application->getServiceManager()->get('view-helper-manager');
     foreach ($viewPluginManager->getCanonicalNames() as $name) {
         $helper = $viewPluginManager->get($name);
         $this->viewHelpers[$name] = get_class($helper);
     }
 }
Example #9
0
 public function testInitCurrentLocaleWithLangOnQuery()
 {
     $expected = 'es_ES';
     $e = $this->createMvcEvent($expected);
     $this->assertEquals('id_ID', $this->app->getServiceManager()->get('translator')->getLocale());
     $this->module->initCurrentLocale($e);
     // Test that current locale has changed to the one in the query
     $this->assertEquals($expected, $this->app->getServiceManager()->get('translator')->getLocale());
 }
Example #10
0
 public function it_aborts_bootstrap_on_console(MvcEvent $event, Application $application, ServiceLocatorInterface $serviceLocator, AccessListener $listener, EventManager $eventManager)
 {
     Console::overrideIsConsole(true);
     $application->getEventManager()->willReturn($eventManager);
     $serviceLocator->get(AccessListener::class)->willReturn($listener);
     $application->getServiceManager()->willReturn($serviceLocator);
     $event->getApplication()->willReturn($application);
     $listener->attach($eventManager)->shouldNotBeCalled();
     $this->onBootstrap($event);
 }
 /**
  * Get the application object
  * @return \Zend\Mvc\Application
  */
 public static function getApplication()
 {
     if (self::$application instanceof \Zend\Mvc\ApplicationInterface) {
         return self::$application;
     }
     self::$application = \Zend\Mvc\Application::init(self::getApplicationConfig());
     $oEventManager = self::$application->getEventManager();
     $oEventManager->detach(self::$application->getServiceManager()->get('SendResponseListener'));
     return self::$application;
 }
Example #12
0
    /**
     * @param string $abstractController
     */
    public function generateControllerSnub($abstractController)
    {
        /** @var \Zend\Mvc\Controller\PluginManager $controllerPluginManager */
        $controllerPluginManager = $this->application->getServiceManager()->get('controller-plugin-manager');
        $methods = [];
        foreach ($controllerPluginManager->getCanonicalNames() as $key => $name) {
            $pluginClass = $controllerPluginManager->get($name);
            $methods[$key] = get_class($pluginClass);
        }
        $className = str_replace('\\', '', $abstractController);
        $generated = date("Y-m-d H:i:s");
        $snub = <<<SNUB
<?php

/**
 * Generated on {$generated}
 */
namespace Snub;

/**

SNUB;
        foreach ($methods as $name => $returns) {
            if (strpos($returns, '\\') !== 0) {
                $returns = '\\' . $returns;
            }
            $snub .= " * @method {$returns} {$name}()" . PHP_EOL;
        }
        $snub .= <<<SNUB
 * @method \\Zend\\Http\\PhpEnvironment\\Request getRequest()
 * @property \\Zend\\Http\\PhpEnvironment\\Request request
 * @method \\Zend\\Http\\PhpEnvironment\\Response getResponse()
 * @property \\Zend\\Http\\PhpEnvironment\\Response response
 */
abstract class Snubbed{$className} extends {$abstractController} {}


SNUB;
        $this->fileWriter->write('.ide/Snub/Snubbed' . $className . '.php', $snub);
    }
 public static function getServiceManager()
 {
     return self::$applicationInstance->getServiceManager();
 }
 /**
  * @return array
  */
 public function getModules()
 {
     /** @var $moduleManager \Zend\ModuleManager\ModuleManager */
     $moduleManager = $this->application->getServiceManager()->get('ModuleManager');
     return $moduleManager->getLoadedModules();
 }
 /**
  * @return DataMapperManager
  */
 public function getDataMapperManager()
 {
     return $this->application->getServiceManager()->get(DataMapperManager::class);
 }
 public function testServiceManagerIsPopulated()
 {
     $this->assertSame($this->serviceManager, $this->application->getServiceManager());
 }
Example #17
0
 public static function init()
 {
     static::initAutoloader();
     static::$app = Zend\Mvc\Application::init(static::$app_config);
     static::$app->getServiceManager()->get('config');
 }
 public function getServiceManager()
 {
     return $this->applicationInstance->getServiceManager();
 }