本文整理匯總了PHP中Zend\Mvc\MvcEvent::setApplication方法的典型用法代碼示例。如果您正苦於以下問題:PHP MvcEvent::setApplication方法的具體用法?PHP MvcEvent::setApplication怎麽用?PHP MvcEvent::setApplication使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Mvc\MvcEvent
的用法示例。
在下文中一共展示了MvcEvent::setApplication方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: bootstrap
public function bootstrap()
{
$event = new MvcEvent();
$event->setApplication($this);
$event->setTarget($this);
$this->getEventManager()->trigger(MvcEvent::EVENT_BOOTSTRAP, $event);
}
示例2: testDoesNotLimitDispatchErrorEventToOnlyOneListener
public function testDoesNotLimitDispatchErrorEventToOnlyOneListener()
{
$eventManager = new EventManager();
$application = $this->prophesize(Application::class);
$application->getEventManager()->willReturn($eventManager);
$event = new MvcEvent();
$event->setApplication($application->reveal());
$guard = new DummyGuard();
$guard->attach($eventManager);
$eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $event) {
$event->setParam('first-listener', true);
});
$eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $event) {
$event->setParam('second-listener', true);
});
// attach listener with lower priority than DummyGuard
$eventManager->attach(MvcEvent::EVENT_ROUTE, function (MvcEvent $event) {
$this->fail('should not be called, because guard should stop propagation');
}, DummyGuard::EVENT_PRIORITY - 1);
$event->setName(MvcEvent::EVENT_ROUTE);
$eventManager->triggerEvent($event);
$this->assertTrue($event->getParam('first-listener'));
$this->assertTrue($event->getParam('second-listener'));
$this->assertTrue($event->propagationIsStopped());
}
示例3: setUp
public function setUp()
{
StaticEventManager::resetInstance();
$mockSharedEventManager = $this->getMock('Zend\EventManager\SharedEventManagerInterface');
$mockSharedEventManager->expects($this->any())->method('getListeners')->will($this->returnValue(array()));
$mockEventManager = $this->getMock('Zend\EventManager\EventManagerInterface');
$mockEventManager->expects($this->any())->method('getSharedManager')->will($this->returnValue($mockSharedEventManager));
$mockApplication = $this->getMock('Zend\Mvc\ApplicationInterface');
$mockApplication->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager));
$event = new MvcEvent();
$event->setApplication($mockApplication);
$event->setRequest(new Request());
$event->setResponse(new Response());
$routeMatch = new RouteMatch(array('action' => 'test'));
$routeMatch->setMatchedRouteName('some-route');
$event->setRouteMatch($routeMatch);
$locator = new Locator;
$locator->add('forward', function () {
return new ForwardController();
});
$this->controller = new SampleController();
$this->controller->setEvent($event);
$this->controller->setServiceLocator($locator);
$this->plugin = $this->controller->plugin('forward');
}
示例4: bootstrap
public function bootstrap()
{
$event = new MvcEvent();
$event->setApplication($this);
$event->setTarget($this);
$this->getEventManager()->trigger('bootstrap', $event);
}
示例5: getMvcEvent
/**
* @param EventManager $em
* @return MvcEvent
*/
protected function getMvcEvent($em)
{
$event = new MvcEvent();
$serviceManager = new ServiceManager();
$serviceManager->setService('EventManager', $em)->setService('Request', new HttpRequest())->setService('Response', new HttpResponse());
$application = new Application(array(), $serviceManager);
$event->setApplication($application);
return $event;
}
示例6: testCanStartSession
public function testCanStartSession()
{
$event = new MvcEvent();
$event->setApplication($this->getApplication());
$event->setRequest(new Request());
$sessionListener = new RouteListener();
$sessionListener->startSession($event);
$this->assertArrayHasKey('__ZF', $_SESSION);
}
示例7: setUpMvcEvent
public function setUpMvcEvent($app, $request, $response)
{
$event = new MvcEvent();
$event->setTarget($app);
$event->setApplication($app)->setRequest($request)->setResponse($response);
$r = new ReflectionProperty($app, 'event');
$r->setAccessible(true);
$r->setValue($app, $event);
return $app;
}
示例8: testCurrentRouteNameViewModelVariableIsSetOnBootstrap
public function testCurrentRouteNameViewModelVariableIsSetOnBootstrap()
{
$currentRouteName = self::class;
$application = $this->setUpApplication($currentRouteName);
$mvcEvent = new MvcEvent();
$mvcEvent->setApplication($application);
$module = new Module();
$module->onBootstrap($mvcEvent);
$viewModel = $mvcEvent->getViewModel();
$this->assertEquals($currentRouteName, $viewModel->getVariable('__currentRouteName'));
}
示例9: testPluginManagers
public function testPluginManagers()
{
$sm = $this->getServiceManager();
$app = $sm->get('Application');
$event = new MvcEvent();
$event->setApplication($app);
$module = new Module();
$module->onBootstrap($event);
$connectionManager = $sm->get('HumusAmqpModule\\PluginManager\\Connection');
$this->assertInstanceOf('HumusAmqpModule\\PluginManager\\Connection', $connectionManager);
}
示例10: testOnBootstrapListenersWithConsoleRequest
public function testOnBootstrapListenersWithConsoleRequest()
{
$module = new Module();
$application = $this->createApplication();
$sm = $application->getServiceManager();
$sm->setAllowOverride(true);
$sm->setService('Request', new ConsoleRequest());
$em = $application->getEventManager();
$event = new MvcEvent();
$event->setApplication($application);
$module->onBootstrap($event);
}
示例11: setUp
protected function setUp()
{
$serviceManager = Bootstrap::getServiceManager();
$this->controller = new IndexController();
$this->request = new Request();
$this->routeMatch = new RouteMatch(array('controller' => 'index'));
$this->event = new MvcEvent();
$config = $serviceManager->get('Config');
$routerConfig = isset($config['router']) ? $config['router'] : array();
$router = HttpRouter::factory($routerConfig);
$serviceManager->setAllowOverride(true);
$serviceManager->setService('AuthService', new AuthenticationService(new Storage\NonPersistent(), new TestAdapter()));
$albumTableMock = $this->getMockBuilder('Zend\\Mvc\\Controller\\ControllerManager')->disableOriginalConstructor()->getMock();
$albumTableMock->expects($this->any())->method('get')->will($this->returnValue($this->controller));
$serviceManager->setService('ControllerManager', $albumTableMock);
$this->event->setApplication(new Application($config, $serviceManager));
$this->event->setRouter($router);
$this->event->setRouteMatch($this->routeMatch);
$this->controller->setEvent($this->event);
$this->controller->setServiceLocator($serviceManager);
}
示例12: setUp
public function setUp()
{
StaticEventManager::resetInstance();
$mockSharedEventManager = $this->getMock('Zend\\EventManager\\SharedEventManagerInterface');
$mockSharedEventManager->expects($this->any())->method('getListeners')->will($this->returnValue(array()));
$mockEventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface');
$mockEventManager->expects($this->any())->method('getSharedManager')->will($this->returnValue($mockSharedEventManager));
$mockApplication = $this->getMock('Zend\\Mvc\\ApplicationInterface');
$mockApplication->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager));
$event = new MvcEvent();
$event->setApplication($mockApplication);
$event->setRequest(new Request());
$event->setResponse(new Response());
$routeMatch = new RouteMatch(array('action' => 'test'));
$routeMatch->setMatchedRouteName('some-route');
$event->setRouteMatch($routeMatch);
$services = new Locator();
$plugins = $this->plugins = new PluginManager();
$plugins->setServiceLocator($services);
$controllers = $this->controllers = new ControllerManager();
$controllers->setFactory('forward', function () use($plugins) {
$controller = new ForwardController();
$controller->setPluginManager($plugins);
return $controller;
});
$controllers->setInvokableClass('ZendTest\\Mvc\\Controller\\TestAsset\\ForwardFq', 'ZendTest\\Mvc\\Controller\\TestAsset\\ForwardFqController');
$controllers->setServiceLocator($services);
$controllerLoader = function () use($controllers) {
return $controllers;
};
$services->add('ControllerLoader', $controllerLoader);
$services->add('ControllerManager', $controllerLoader);
$services->add('ControllerPluginManager', function () use($plugins) {
return $plugins;
});
$services->add('Zend\\ServiceManager\\ServiceLocatorInterface', function () use($services) {
return $services;
});
$services->add('EventManager', function () use($mockEventManager) {
return $mockEventManager;
});
$services->add('SharedEventManager', function () use($mockSharedEventManager) {
return $mockSharedEventManager;
});
$this->controller = new SampleController();
$this->controller->setEvent($event);
$this->controller->setServiceLocator($services);
$this->controller->setPluginManager($plugins);
$this->plugin = $this->controller->plugin('forward');
}
示例13: testOnBootstrap
public function testOnBootstrap()
{
$event = new MvcEvent();
$application = new Application([], Bootstrap::getServiceManager());
$em = new EventManager();
$application->setEventManager($em);
$event->setApplication($application);
$isConsole = Console::isConsole();
Console::overrideIsConsole(false);
$this->module->onBootstrap($event);
Console::overrideIsConsole($isConsole);
$this->assertCount(1, $em->getListeners(MvcEvent::EVENT_DISPATCH));
$this->assertCount(1, $em->getListeners(MvcEvent::EVENT_RENDER));
}
示例14: __Construct
public function __Construct()
{
$env = getenv("DB");
switch ($env) {
case $env == "sqlite":
$dbfilename = "schema.sqlite.sql";
$configFileName = "sqlite.config.php";
break;
case $env == "mysql":
$dbfilename = "schema.sql";
$configFileName = "mysql.config.php";
break;
case $env == "pgsql":
$dbfilename = "schema.pgsql.sql";
$configFileName = "pgsql.config.php";
break;
}
$configuration = (include __DIR__ . '/TestConfiguration.php');
if (isset($configuration['output_buffering']) && $configuration['output_buffering']) {
ob_start();
// required to test sessions
}
$this->serviceManager = new ServiceManager(new ServiceManagerConfig(isset($configuration['service_manager']) ? $configuration['service_manager'] : array()));
$this->serviceManager->setService('ApplicationConfig', $configuration);
$this->serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
/** @var $moduleManager \Zend\ModuleManager\ModuleManager */
$moduleManager = $this->serviceManager->get('ModuleManager');
$moduleManager->loadModules();
$this->serviceManager->setAllowOverride(true);
$application = $this->serviceManager->get('Application');
$event = new MvcEvent();
$event->setTarget($application);
$event->setApplication($application)->setRequest($application->getRequest())->setResponse($application->getResponse())->setRouter($this->serviceManager->get('Router'));
/// lets create user's table
$em = $this->serviceManager->get("doctrine.entitymanager.orm_default");
$conn = $em->getConnection();
if (file_exists(__DIR__ . "/../vendor/zf-commons/zfc-user/data/{$dbfilename}")) {
$sql = file_get_contents(__DIR__ . "/../vendor/zf-commons/zfc-user/data/{$dbfilename}");
} elseif (file_exists(__DIR__ . "/../../../../vendor/zf-commons/zfc-user/data/{$dbfilename}")) {
$sql = file_get_contents(__DIR__ . "/../../../../vendor/zf-commons/zfc-user/data/{$dbfilename}");
} else {
throw new \Exception("please check the zfc user sql file", 500);
}
$stmt = $conn->prepare($sql);
try {
$stmt->execute();
} catch (Exception $exc) {
}
}
示例15: testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingResult
public function testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingResult()
{
//Register console service
$sm = new ServiceManager();
$sm->setService('console', new ConsoleAdapter());
$mockApplication = new MockApplication();
$mockApplication->setServiceManager($sm);
$event = new MvcEvent();
$event->setApplication($mockApplication);
$model = new Model\ViewModel(array('content' => 'Page not found'));
$response = new Response();
$event->setResult($model);
$event->setResponse($response);
$this->strategy->render($event);
$content = $response->getContent();
$this->assertNotContains('Page not found', $content);
}