本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::setFactory方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::setFactory方法的具体用法?PHP ServiceManager::setFactory怎么用?PHP ServiceManager::setFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\ServiceManager\ServiceManager
的用法示例。
在下文中一共展示了ServiceManager::setFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setup
public function setup()
{
parent::setup();
$config = (include 'config/application.config.php');
$config['module_listener_options']['config_static_paths'] = array(getcwd() . '/config/test.config.php');
if (file_exists(__DIR__ . '/config/test.config.php')) {
$moduleConfig = (include __DIR__ . '/config/test.config.php');
array_unshift($config['module_listener_options']['config_static_paths'], $moduleConfig);
}
$this->serviceManager = new ServiceManager(new ServiceManagerConfig(isset($config['service_manager']) ? $config['service_manager'] : array()));
$this->serviceManager->setService('ApplicationConfig', $config);
$this->serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
$moduleManager = $this->serviceManager->get('ModuleManager');
$moduleManager->loadModules();
$this->routes = array();
foreach ($moduleManager->getModules() as $m) {
$moduleConfig = (include __DIR__ . '/../../../../' . ucfirst($m) . '/config/module.config.php');
if (isset($moduleConfig['router'])) {
foreach ($moduleConfig['router']['routes'] as $key => $name) {
$this->routes[$key] = $name;
}
}
}
$this->serviceManager->setAllowOverride(true);
$this->application = $this->serviceManager->get('Application');
$this->event = new MvcEvent();
$this->event->setTarget($this->application);
$this->event->setApplication($this->application)->setRequest($this->application->getRequest())->setResponse($this->application->getResponse())->setRouter($this->serviceManager->get('Router'));
$this->createDatabase();
}
示例2: setup
public function setup()
{
parent::setup();
$pathDir = getcwd() . "/";
$config = (include $pathDir . 'config/application.config.php');
$this->serviceManager = new ServiceManager(new ServiceManagerConfig(isset($config['service_manager']) ? $config['service_manager'] : array()));
$this->serviceManager->setService('ApplicationConfig', $config);
$this->serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
$moduleManager = $this->serviceManager->get('ModuleManager');
$moduleManager->loadModules();
$this->routes = array();
$this->modules = $moduleManager->getModules();
foreach ($this->filterModules() as $m) {
$moduleConfig = (include $pathDir . 'module/' . ucfirst($m) . '/config/module.config.php');
if (isset($moduleConfig['router'])) {
foreach ($moduleConfig['router']['routes'] as $key => $name) {
$this->routes[$key] = $name;
}
}
}
$this->serviceManager->setAllowOverride(true);
$this->application = $this->serviceManager->get('Application');
$this->event = new MvcEvent();
$this->event->setTarget($this->application);
$this->event->setApplication($this->application)->setRequest($this->application->getRequest())->setResponse($this->application->getResponse())->setRouter($this->serviceManager->get('Router'));
$this->em = $this->serviceManager->get('Doctrine\\ORM\\EntityManager');
foreach ($this->filterModules() as $m) {
$this->createDatabase($m);
}
}
示例3: configureServiceManager
public function configureServiceManager(\Zend\ServiceManager\ServiceManager $serviceManager)
{
$serviceManager->setFactory('A', function () {
return new A();
});
$serviceManager->setShared('A', true);
$serviceManager->setFactory('B', function ($serviceManager) {
return new B($serviceManager->get('A'));
});
$serviceManager->setShared('B', false);
}
示例4: getServiceManager
/**
* Builds a new service manager
*/
public static function getServiceManager()
{
$serviceManager = new ServiceManager(new ServiceManagerConfig(isset(static::$config['service_manager']) ? static::$config['service_manager'] : array()));
$serviceManager->setService('ApplicationConfig', static::$config);
$serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
$serviceManager->setFactory('ModuleListener', 'Zend\\Mvc\\Service\\ModuleListenerFactory');
/** @var $moduleManager \Zend\ModuleManager\ModuleManager */
$moduleManager = $serviceManager->get('ModuleManager');
$moduleManager->loadModules();
//$serviceManager->setAllowOverride(true);
return $serviceManager;
}
示例5: testWillInstantiateFromFQCN
public function testWillInstantiateFromFQCN()
{
$name = 'testFactory';
$factory = new AuthenticationServiceFactory($name);
$objectManager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
$serviceManager = new ServiceManager();
$serviceManager->setService('Configuration', array('doctrine' => array('authentication' => array($name => array('objectManager' => $objectManager, 'identityClass' => 'DoctrineModuleTest\\Authentication\\Adapter\\TestAsset\\IdentityObject', 'identityProperty' => 'username', 'credentialProperty' => 'password')))));
$serviceManager->setFactory('doctrine.authenticationadapter.' . $name, new AdapterFactory($name));
$serviceManager->setFactory('doctrine.authenticationstorage.' . $name, new StorageFactory($name));
$authenticationService = $factory->createService($serviceManager);
$this->assertInstanceOf('Zend\\Authentication\\AuthenticationService', $authenticationService);
}
示例6: setUp
public function setUp()
{
$formElementManagerFactory = new FormElementManagerFactory();
$config = new ArrayObject(array('di' => array()));
$this->services = new ServiceManager();
$this->services->setService('Zend\\ServiceManager\\ServiceLocatorInterface', $this->services);
$this->services->setFactory('FormElementManager', $formElementManagerFactory);
$this->services->setService('Config', $config);
$this->services->setFactory('Di', new DiFactory());
$this->services->setFactory('DiAbstractServiceFactory', new DiAbstractServiceFactoryFactory());
$this->services->setFactory('DiServiceInitializer', new DiServiceInitializerFactory());
}
示例7: setUp
public function setUp()
{
$loaderFactory = new ControllerLoaderFactory();
$config = new ArrayObject(array('di' => array()));
$this->services = new ServiceManager();
$this->services->setService('Zend\\ServiceManager\\ServiceLocatorInterface', $this->services);
$this->services->setFactory('ControllerLoader', $loaderFactory);
$this->services->setService('Config', $config);
$this->services->setFactory('ControllerPluginManager', new ControllerPluginManagerFactory());
$this->services->setFactory('Di', new DiFactory());
$this->services->setFactory('EventManager', new EventManagerFactory());
$this->services->setInvokableClass('SharedEventManager', 'Zend\\EventManager\\SharedEventManager');
}
示例8: testInitLoadsEnvironmentVariablesFromWorkingDirectory
/**
* @expectedException \Abacaphiliac\ZendPhpDotEnv\Exception\InvalidWorkingDirectoryPathException
*/
public function testInitLoadsEnvironmentVariablesFromWorkingDirectory()
{
$serviceLocator = new ServiceManager();
$serviceLocator->setService('ApplicationConfig', array('module_listener_options' => array(), 'modules' => array('Abacaphiliac\\ZendPhpDotEnv')));
$serviceLocator->setFactory('EventManager', new EventManagerFactory());
$serviceLocator->setService('SharedEventManager', new SharedEventManager());
$serviceLocator->setFactory('ServiceListener', '\\Zend\\Mvc\\Service\\ServiceListenerFactory');
$moduleManagerFactory = new ModuleManagerFactory();
$moduleManager = $moduleManagerFactory->createService($serviceLocator);
$module = new Module($constant = null, $variable = null, $file = '.testEnv');
$module->init($moduleManager);
$moduleManager->getEventManager()->trigger(new ModuleEvent(ModuleEvent::EVENT_LOAD_MODULE));
}
示例9: setup
/**
* Faz o setup dos testes. Executado antes de cada teste
* @return void
*/
public function setup()
{
$env = getenv('ENV');
//o jenkins tem configurações especiais
if (!$env || $env != 'jenkins') {
putenv("ENV=testing");
$env = 'testing';
}
putenv('PROJECT_ROOT=' . __DIR__ . '/../../../../../');
parent::setup();
//arquivo de configuração da aplicação
$config = (include __DIR__ . '/../../../../../config/tests.config.php');
$config['module_listener_options']['config_static_paths'] = array();
//cria um novo ServiceManager
$this->serviceManager = new ServiceManager(new ServiceManagerConfig(isset($config['service_manager']) ? $config['service_manager'] : array()));
//configura os serviços básicos no ServiceManager
$this->serviceManager->setService('ApplicationConfig', $config);
$this->serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
//verifica se os módulos possuem rotas configuradas e carrega elas para serem usadas pelo ControllerTestCase
$moduleManager = $this->serviceManager->get('ModuleManager');
$moduleManager->loadModules();
$this->routes = array();
$testConfig = false;
//carrega as rotas dos módulos
foreach ($moduleManager->getLoadedModules() as $m) {
$moduleConfig = $m->getConfig();
$this->getModuleRoutes($moduleConfig);
$moduleName = explode('\\', get_class($m));
$moduleName = $moduleName[0];
//verifica se existe um arquivo de configuração específico no módulo para testes
if (file_exists(getcwd() . '/module/' . ucfirst($moduleName) . '/config/test.config.php')) {
$testConfig = (include getcwd() . '/module/' . ucfirst($moduleName) . '/config/test.config.php');
array_unshift($config['module_listener_options']['config_static_paths'], $testConfig[$env]);
}
}
if (!$testConfig) {
$config['module_listener_options']['config_static_paths'] = array(getcwd() . '/config/tests.config.php');
}
$this->config = (include $config['module_listener_options']['config_static_paths'][0]);
$this->serviceManager->setAllowOverride(true);
//instancia a aplicação e configura os eventos e rotas
$this->application = $this->serviceManager->get('Application');
$this->event = new MvcEvent();
$this->event->setTarget($this->application);
$this->event->setApplication($this->application)->setRequest($this->application->getRequest())->setResponse($this->application->getResponse())->setRouter($this->serviceManager->get('Router'));
$this->entityManager = $this->getEntityManager();
$this->dropDatabase();
$this->createDatabase();
}
示例10: getServiceLocator
public function getServiceLocator(array $config = array())
{
$serviceLocator = new ServiceManager();
$serviceLocator->setFactory('MQUtil\\Service\\ShortUrl', 'MQUtil\\Service\\ShortUrlFactory');
$serviceLocator->setService('config', $config);
return $serviceLocator;
}
示例11: testGet
public function testGet()
{
// Via container
$this->container->foo = [];
$this->assertEquals([], $this->container->get('foo'));
// Via service manager
$this->sm->setService('foo', new \stdClass());
$this->sm->setAlias('bar', 'foo');
$this->assertInstanceOf('stdClass', $this->container->get('bar'));
$this->sm->setFactory('factory', function (ServiceManager $sm) {
return $sm->get('bar');
});
$this->assertInstanceOf('stdClass', $this->container->get('factory'));
$this->sm->setInvokableClass('invokable', 'stdClass');
$this->assertInstanceOf('stdClass', $this->container->get('invokable'));
}
示例12: getServiceManager
/**
* Retrieves a new ServiceManager instance
*
* @param array|null $configuration
* @return ServiceManager
*/
public function getServiceManager(array $configuration = null)
{
$configuration = $configuration ?: static::getConfiguration();
$serviceManager = new ServiceManager(new ServiceManagerConfig(isset($configuration['service_manager']) ? $configuration['service_manager'] : array()));
$serviceManager->setService('ApplicationConfig', $configuration);
$serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
return $serviceManager;
}
示例13: getServiceLocator
public function getServiceLocator(array $config = array())
{
$config = array('mq_locale' => $config);
$serviceLocator = new ServiceManager();
$serviceLocator->setFactory('MQLocale\\Locale\\Detector', 'MQLocale\\Service\\DetectorFactory');
$serviceLocator->setService('config', $config);
return $serviceLocator;
}
示例14: testConstructedFromConfig
/**
* @covers \Zend\Navigation\MvcNavigationFactory
*/
public function testConstructedFromConfig()
{
$argument = new Config\Config(array(array('label' => 'Page 1', 'uri' => 'page1.html'), array('label' => 'Page 2', 'uri' => 'page2.html'), array('label' => 'Page 3', 'uri' => 'page3.html')));
$factory = new ConstructedNavigationFactory($argument);
$this->serviceManager->setFactory('Navigation', $factory);
$container = $this->serviceManager->get('Navigation');
$this->assertEquals(3, $container->count());
}
示例15: testWillInitializeDiAndDiAbstractFactory
public function testWillInitializeDiAndDiAbstractFactory()
{
$serviceManager = new ServiceManager();
$serviceManager->setService('Config', array('di' => array('')));
$serviceManager->setFactory('Di', new DiFactory());
$di = $serviceManager->get('Di');
$this->assertInstanceOf('Zend\\Di\\Di', $di);
}