本文整理汇总了PHP中Zend\EventManager\EventManager::setSharedManager方法的典型用法代码示例。如果您正苦于以下问题:PHP EventManager::setSharedManager方法的具体用法?PHP EventManager::setSharedManager怎么用?PHP EventManager::setSharedManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\EventManager\EventManager
的用法示例。
在下文中一共展示了EventManager::setSharedManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
// Store original autoloaders
$this->loaders = spl_autoload_functions();
if (!is_array($this->loaders)) {
// spl_autoload_functions does not return empty array when no
// autoloaders registered...
$this->loaders = array();
}
// Store original include_path
$this->includePath = get_include_path();
$autoloader = new ModuleAutoloader(array(dirname(__DIR__) . '/TestAsset'));
$autoloader->register();
$this->sharedEvents = new SharedEventManager();
$this->moduleManager = new ModuleManager(array('ListenerTestModule'));
$this->moduleManager->getEventManager()->setSharedManager($this->sharedEvents);
$this->moduleManager->getEventManager()->attach('loadModule.resolve', new ModuleResolverListener(), 1000);
$this->application = new MockApplication();
$events = new EventManager(array('Zend\\Mvc\\Application', 'ZendTest\\Module\\TestAsset\\MockApplication', 'application'));
$events->setSharedManager($this->sharedEvents);
$this->application->setEventManager($events);
$this->serviceManager = new ServiceManager();
$this->serviceManager->setService('ModuleManager', $this->moduleManager);
$this->application->setServiceManager($this->serviceManager);
}
示例2: createService
/**
* Create an instance of EventManagerProxy
*
* @param ServiceLocatorInterface $serviceLocator
*
* @return EventManagerProxy
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$proxy = new EventManagerProxy();
$em = new EventManager();
$em->setSharedManager($serviceLocator->get('SharedEventManager'));
$proxy->setEventManager($em);
return $proxy;
}
示例3: testAttach
public function testAttach()
{
$sharedEvents = new SharedEventManager();
$events = new EventManager();
$events->setSharedManager($sharedEvents);
$listener = new AccessListener();
$listener->attach($events);
$this->assertCount(1, $sharedEvents->getListeners('SporkTools', MvcEvent::EVENT_DISPATCH));
}
示例4: setUp
public function setUp()
{
$this->module = new Module();
$this->app = $this->getMockBuilder('Zend\\Mvc\\Application')->disableOriginalConstructor()->getMock();
$sm = new ServiceManager(new Config(['services' => ['translator' => Translator::factory(['locale' => 'id_ID'])]]));
$this->app->expects($this->any())->method('getServiceManager')->willReturn($sm);
$em = new EventManager();
$em->setSharedManager(new SharedEventManager());
$this->app->expects($this->any())->method('getEventManager')->willReturn($em);
}
示例5: marshalEventManager
public function marshalEventManager()
{
$r = new ReflectionClass(EventManager::class);
if ($r->hasMethod('setSharedManager')) {
$eventManager = new EventManager();
$eventManager->setSharedManager(new SharedEventManager());
return $eventManager;
}
return new EventManager(new SharedEventManager());
}
示例6: testCanAttachListeners
public function testCanAttachListeners()
{
$mockListener = $this->getMock('EventLogger\\Log\\Listener\\LogListener');
$serviceManager = new ServiceManager();
$serviceManager->setService('EventLogger\\Log\\Listener\\AppListener', $mockListener);
$serviceManager->setService('EventLogger\\Log\\Listener\\DispatchErrorListener', $mockListener);
$eventManager = new EventManager();
$eventManager->setSharedManager(new SharedEventManager());
$listenerAggregate = new ListenerAggregate($serviceManager);
$listenerAggregate->attach($eventManager);
}
示例7: setUp
public function setUp()
{
$this->module = new Module();
$app = $this->prophesize('Zend\\Mvc\\Application');
$sm = new ServiceManager(new Config(['services' => ['translator' => Translator::factory(['locale' => 'id_ID'])]]));
$app->getServiceManager()->willReturn($sm);
$em = new EventManager();
$em->setSharedManager(new SharedEventManager());
$app->getEventManager()->willReturn($em);
$this->app = $app->reveal();
}
示例8: createService
/**
* Create an EventManager instance
*
* Creates a new EventManager instance, seeding it with a shared instance
* of SharedEventManager.
*
* @param ServiceLocatorInterface $serviceLocator
* @return EventManager
* @throws ServiceNotFoundException
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if ($serviceLocator instanceof AbstractPluginManager) {
$serviceLocator = $serviceLocator->getServiceLocator();
}
/** @var SharedEventManagerInterface $sharedEventManager */
$sharedEventManager = $serviceLocator->get('SharedEventManager');
$em = new EventManager();
$em->setSharedManager($sharedEventManager);
return $em;
}
示例9: createEventManager
/**
* Create and return an EventManager composing the shared event manager instance.
*
* @return EventManager
*/
private function createEventManager()
{
$r = new \ReflectionClass(EventManager::class);
if ($r->hasMethod('setSharedManager')) {
// zend-eventmanager v2 initialization
$eventManager = new EventManager();
$eventManager->setSharedManager($this->sharedEventManager);
return $eventManager;
}
// zend-eventmanager v3 initialization
return new EventManager($this->sharedEventManager);
}
示例10: __invoke
/**
* Create an EventManager instance
*
* Creates a new EventManager instance, seeding it with a shared instance
* of SharedEventManager.
*
* @param ContainerInterface $container
* @param string $name
* @param null|array $options
* @return EventManager
*/
public function __invoke(ContainerInterface $container, $name, array $options = null)
{
if ($this->acceptsSharedManagerToConstructor()) {
// zend-eventmanager v3
return new EventManager($container->has('SharedEventManager') ? $container->get('SharedEventManager') : null);
}
// zend-eventmanager v2
$events = new EventManager();
if ($container->has('SharedEventManager')) {
$events->setSharedManager($container->get('SharedEventManager'));
}
return $events;
}
示例11: createEventManager
/**
* @param ContainerInterface $container
*
* @return EventManager
*/
protected function createEventManager(ContainerInterface $container)
{
if ($this->acceptsSharedManagerToConstructor()) {
// zend-eventmanager v3
return new EventManager($container->has('SharedEventManager') ? $container->get('SharedEventManager') : null);
}
// zend-eventmanager v2
$events = new EventManager();
if ($container->has('SharedEventManager')) {
$events->setSharedManager($container->get('SharedEventManager'));
}
return $events;
}
示例12: setUp
protected function setUp()
{
$module = new Module();
$events = new EventManager();
$sharedEvents = new SharedEventManager();
$events->setSharedManager($sharedEvents);
$plugins = new ControllerPluginManager();
$this->serviceManager = new ServiceManager();
$this->serviceManager->setService('Zend\\ServiceManager\\ServiceLocatorInterface', $this->serviceManager);
$this->serviceManager->setService('EventManager', $events);
$this->serviceManager->setService('SharedEventManager', $sharedEvents);
$this->serviceManager->setService('ControllerPluginManager', $plugins);
$this->controllerManager = new ControllerManager(new Config($module->getControllerConfig()));
$this->controllerManager->setServiceLocator($this->serviceManager);
$this->controllerManager->addPeeringServiceManager($this->serviceManager);
}
示例13: testEventListenerIsAttached
public function testEventListenerIsAttached()
{
$module = new Module();
$mvcEvent = $this->getMock('Zend\\EventManager\\EventInterface');
$application = $this->getMock('Zend\\Mvc\\Application', [], [], '', false);
$eventManager = new EventManager();
$eventManager->setSharedManager(new SharedEventManager());
$serviceManager = new ServiceManager();
$mvcEvent->expects($this->once())->method('getParam')->with('application')->will($this->returnValue($application));
$application->expects($this->once())->method('getEventManager')->will($this->returnValue($eventManager));
$application->expects($this->once())->method('getServiceManager')->will($this->returnValue($serviceManager));
$eventManager->addIdentifiers(['ZfcUser\\Service\\User']);
$event = new Event();
$event->setName('register.post');
$userRegistrationService = $this->getMock('HtUserRegistration\\Service\\UserRegistrationServiceInterface');
$serviceManager->setService('HtUserRegistration\\UserRegistrationService', $userRegistrationService);
$userRegistrationService->expects($this->once())->method('onUserRegistration')->with($event);
$module->onBootstrap($mvcEvent);
$eventManager->trigger($event);
}
示例14: setUp
public function setUp()
{
$this->loaders = spl_autoload_functions();
if (!is_array($this->loaders)) {
// spl_autoload_functions does not return empty array when no
// autoloaders registered...
$this->loaders = array();
}
// Store original include_path
$this->includePath = get_include_path();
$autoloader = new ModuleAutoloader(array(dirname(__DIR__) . '/TestAsset'));
$autoloader->register();
$sharedEvents = new SharedEventManager();
$this->moduleManager = new ModuleManager(array());
$this->moduleManager->getEventManager()->setSharedManager($sharedEvents);
$this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, new ModuleResolverListener(), 1000);
$this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE, new OnBootstrapListener(), 1000);
$this->application = new MockApplication();
$events = new EventManager(array('Zend\\Mvc\\Application', 'ZendTest\\Module\\TestAsset\\MockApplication', 'application'));
$events->setSharedManager($sharedEvents);
$this->application->setEventManager($events);
}
示例15: createEventManager
/**
* Create and return an event manager instance.
*
* Ensures that the returned event manager has a shared manager
* composed.
*
* @return EventManager
*/
private function createEventManager()
{
$r = new ReflectionClass(EventManager::class);
if ($r->hasMethod('setSharedManager')) {
$events = new EventManager();
$events->setSharedManager(new SharedEventManager());
} else {
$events = new EventManager(new SharedEventManager());
}
$this->setEventManager($events);
return $events;
}