getRequest() public method

Get the request object
public getRequest ( ) : Zend\Stdlib\RequestInterface
return Zend\Stdlib\RequestInterface
Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
 public function __construct(HelperPluginManager $pluginManager)
 {
     $this->pluginManager = $pluginManager;
     $this->serviceManager = $pluginManager->getServiceLocator();
     $this->app = $pluginManager->getServiceLocator()->get('Application');
     $this->request = $this->app->getRequest();
     $this->event = $this->app->getMvcEvent();
     $this->em = $this->serviceManager->get('Doctrine\\ORM\\EntityManager');
     $this->translator = $this->serviceManager->get('translator');
 }
 /**
  * Return the redirect from param.
  * First checks GET then POST
  * @return string
  */
 private function getRedirectRouteFromRequest()
 {
     $request = $this->application->getRequest();
     $redirect = $request->getQuery('redirect');
     if ($redirect && $this->routeExists($redirect)) {
         return $redirect;
     }
     $redirect = $request->getPost('redirect');
     if ($redirect && $this->routeExists($redirect)) {
         return $redirect;
     }
     return false;
 }
 /**
  * Return the redirect from param.
  * First checks GET then POST
  * @return string
  */
 private function getRedirectUrlFromRequest()
 {
     $request = $this->application->getRequest();
     $redirect = $request->getQuery('redirect');
     if ($redirect && $this->urlWhitelisted($redirect)) {
         return $redirect;
     }
     $redirect = $request->getPost('redirect');
     if ($redirect && $this->urlWhitelisted($redirect)) {
         return $redirect;
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * @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));
     }
 }
Exemplo n.º 6
0
 /**
  * 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();
 }
Exemplo n.º 7
0
 /**
  * When application is not available, one will be initialized to respond to
  * the esi request.
  *
  * @param  Uri                   $uri
  * @return \Zend\Mvc\Application
  */
 public function getApplication(Uri $uri)
 {
     if (!$this->application instanceof Application) {
         $applicationConfig = $this->getEsiApplicationConfigProvider()->getEsiApplicationConfig($uri);
         $this->application = Application::init($applicationConfig);
         // Remove the finish listeners so response header and content is not automatically echo'd
         $this->application->getEventManager()->clearListeners(MvcEvent::EVENT_FINISH);
     }
     // The request needs to be augmented with the URI passed in
     $request = $this->application->getRequest();
     $request->setUri($uri);
     $request->setRequestUri($uri->getPath() . '?' . $uri->getQuery());
     $request->setQuery(new Parameters($uri->getQueryAsArray()));
     return $this->application;
 }
Exemplo n.º 8
0
 public function testBootstrapRegistersConfiguredMvcEvent()
 {
     $this->assertNull($this->application->getMvcEvent());
     $this->application->bootstrap();
     $event = $this->application->getMvcEvent();
     $this->assertInstanceOf('Zend\\Mvc\\MvcEvent', $event);
     $request = $this->application->getRequest();
     $response = $this->application->getResponse();
     $router = $this->serviceManager->get('HttpRouter');
     $this->assertFalse($event->isError());
     $this->assertSame($request, $event->getRequest());
     $this->assertSame($response, $event->getResponse());
     $this->assertSame($router, $event->getRouter());
     $this->assertSame($this->application, $event->getApplication());
     $this->assertSame($this->application, $event->getTarget());
 }
Exemplo n.º 9
0
 /**
  * Collects init params configuration from multiple sources
  *
  * Each next step overwrites previous, whenever data is available, in the following order:
  * 1: ZF application config
  * 2: environment
  * 3: CLI parameters (if the application is running in CLI mode)
  *
  * @param Application $application
  * @return array
  */
 private function extractInitParameters(Application $application)
 {
     $result = [];
     $config = $application->getConfig();
     if (isset($config[self::BOOTSTRAP_PARAM])) {
         $result = $config[self::BOOTSTRAP_PARAM];
     }
     foreach ([State::PARAM_MODE, AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] as $initKey) {
         if (isset($_SERVER[$initKey])) {
             $result[$initKey] = $_SERVER[$initKey];
         }
     }
     $result = array_replace_recursive($result, $this->extractFromCli($application->getRequest()));
     return $result;
 }
Exemplo n.º 10
0
 public function testDefaultRequestObjectContainsUriCreatedFromServerRequestUri()
 {
     $_SERVER['HTTP_HOST'] = 'framework.zend.com';
     $_SERVER['REQUEST_URI'] = '/api/zf-version?test=this';
     $_SERVER['QUERY_STRING'] = 'test=this';
     $app = new Application();
     $req = $app->getRequest();
     $uri = $req->uri();
     $this->assertInstanceOf('Zend\\Uri\\Uri', $uri);
     $this->assertEquals('http', $uri->getScheme());
     $this->assertEquals('framework.zend.com', $uri->getHost());
     $this->assertEquals('/api/zf-version', $uri->getPath());
     $this->assertEquals('test=this', $uri->getQuery());
 }