本文整理汇总了PHP中Zend\Mvc\Application::run方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::run方法的具体用法?PHP Application::run怎么用?PHP Application::run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Application
的用法示例。
在下文中一共展示了Application::run方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUnlocatableControllerLoaderComposedOfAbstractFactory
public function testUnlocatableControllerLoaderComposedOfAbstractFactory()
{
$this->setupPathController();
$controllerLoader = $this->serviceManager->get('ControllerLoader');
$controllerLoader->addAbstractFactory('ZendTest\\Mvc\\Controller\\TestAsset\\UnlocatableControllerLoaderAbstractFactory');
$log = array();
$this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use(&$log) {
$log['error'] = $e->getError();
});
$this->application->run();
$event = $this->application->getMvcEvent();
$dispatchListener = $this->serviceManager->get('DispatchListener');
$return = $dispatchListener->onDispatch($event);
$this->assertArrayHasKey('error', $log);
$this->assertSame('error-controller-not-found', $log['error']);
}
示例2: testEventPropagationStatusIsClearedBetweenEventsDuringRun
/**
* @dataProvider eventPropagation
*/
public function testEventPropagationStatusIsClearedBetweenEventsDuringRun($events)
{
$event = new MvcEvent();
$event->setTarget($this->application);
$event->setApplication($this->application)->setRequest($this->application->getRequest())->setResponse($this->application->getResponse())->setRouter($this->serviceManager->get('Router'));
$event->stopPropagation(true);
// Intentionally not calling bootstrap; setting mvc event
$r = new ReflectionObject($this->application);
$eventProp = $r->getProperty('event');
$eventProp->setAccessible(true);
$eventProp->setValue($this->application, $event);
// Setup listeners that stop propagation, but do nothing else
$marker = array();
foreach ($events as $event) {
$marker[$event] = true;
}
$marker = (object) $marker;
$listener = function ($e) use($marker) {
$marker->{$e->getName()} = $e->propagationIsStopped();
$e->stopPropagation(true);
};
$this->application->getEventManager()->attach($events, $listener);
$this->application->run();
foreach ($events as $event) {
$this->assertFalse($marker->{$event}, sprintf('Assertion failed for event "%s"', $event));
}
}
示例3: testReturnsResponseFromListenerWhenDispatchEventShortCircuits
/**
* @group 2981
*/
public function testReturnsResponseFromListenerWhenDispatchEventShortCircuits()
{
$this->application->bootstrap();
$testResponse = new Response();
$response = $this->application->getResponse();
$events = $this->application->getEventManager();
$events->clearListeners(MvcEvent::EVENT_ROUTE);
$events->attach(MvcEvent::EVENT_DISPATCH, function ($e) use($testResponse) {
$testResponse->setContent('triggered');
return $testResponse;
}, 100);
$self = $this;
$triggered = false;
$events->attach(MvcEvent::EVENT_FINISH, function ($e) use($self, $testResponse, &$triggered) {
$self->assertSame($testResponse, $e->getResponse());
$triggered = true;
});
$this->application->run();
$this->assertTrue($triggered);
}
示例4: testDispatchingInjectsLocatorInLocatorAwareControllers
public function testDispatchingInjectsLocatorInLocatorAwareControllers()
{
$app = new Application();
$request = new Request();
$uri = UriFactory::factory('http://example.local/locator-aware');
$request->setUri($uri);
$app->setRequest($request);
$route = Router\Http\Literal::factory(array('route' => '/locator-aware', 'defaults' => array('controller' => 'locator-aware')));
$router = $app->getRouter();
$router->addRoute('locator-aware', $route);
$locator = new TestAsset\Locator();
$locator->add('locator-aware', function () {
return new TestAsset\LocatorAwareController();
});
$app->setLocator($locator);
$storage = new ArrayObject();
$events = StaticEventManager::getInstance();
$events->attach('ZendTest\\Mvc\\TestAsset\\LocatorAwareController', 'dispatch', function ($e) use($storage) {
$controller = $e->getTarget();
$storage['locator'] = $controller->getLocator();
return $e->getResponse();
}, 100);
$app->run();
$this->assertTrue(isset($storage['locator']));
$this->assertSame($locator, $storage['locator']);
}
示例5: testFinishShouldRunEvenIfDispatchEventReturnsResponse
/**
* @group ZF2-171
*/
public function testFinishShouldRunEvenIfDispatchEventReturnsResponse()
{
$app = new Application();
$response = $app->getResponse();
$events = $app->events();
$events->clearListeners('route');
$events->attach('dispatch', function ($e) use($response) {
return $response;
}, 100);
$token = new stdClass();
$events->attach('finish', function ($e) use($token) {
$token->foo = 'bar';
});
$app->run();
$this->assertTrue(isset($token->foo));
$this->assertEquals('bar', $token->foo);
}
示例6: run
/**
* Run the application.
*
* @return null
*/
public function run()
{
$this->application->run();
}