本文整理汇总了PHP中Zend\Mvc\Application::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::getResponse方法的具体用法?PHP Application::getResponse怎么用?PHP Application::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Application
的用法示例。
在下文中一共展示了Application::getResponse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: __invoke
/**
* @return Response
*/
public function __invoke()
{
$routeMatch = $this->application->getMvcEvent()->getRouteMatch();
$redirect = $this->getRedirect($routeMatch->getMatchedRouteName(), $this->getRedirectRouteFromRequest());
$response = $this->application->getResponse();
$response->getHeaders()->addHeaderLine('Location', $redirect);
$response->setStatusCode(302);
return $response;
}
示例3: testResponseMayBeInjected
public function testResponseMayBeInjected()
{
$app = new Application();
$response = new Response();
$app->setResponse($response);
$this->assertSame($response, $app->getResponse());
}
示例4: 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));
}
}
示例5: 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();
}
示例6: 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);
}
示例7: 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);
}
示例8: getSymfonyResponse
/**
* Gets the response from the service manager and convert it to Symfony.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function getSymfonyResponse()
{
$zendResponse = $this->application->getResponse();
return self::createSymfonyResponse($zendResponse);
}