protected function makeRequest($reqBodyFilename, &$requestEvent = null) { $request = Request::createFromFile($reqBodyFilename); $requestEvent = new RequestEvent(); $requestEvent->setRequest($request); $internalEvent = $this->appPkg->dispatch($requestEvent); return $internalEvent; }
protected function makeRequest($fixture, &$requestEvent = null, $statusCode = 200) { $request = Request::createFromFile($fixture); $requestEvent = new RequestEvent(); $requestEvent->setRequest($request); $internalEvent = $this->appPkg->dispatch($requestEvent); $this->assertEquals($statusCode, $internalEvent->getHttpResponse()->getStatusCode()); return $internalEvent; }
/** * @return boolean */ public function handle(Event\Type\Http\Request $event) { if (!parent::matchRequest($event->getRequest())) { $this->invalidateActions(); return false; } foreach ($this->getApplication()->getValidActions() as $action) { // Skip actions which do not belong to the package if (!$action instanceof AbstractAction) { continue; } if ($action->matchRequest($event->getRequest())) { $this->action = $action; $this->controller = $this->getFactory()->createControllerByAction($action); $this->frontController = $this->getFactory()->createFrontControllerByAction($action); return true; } } $this->triggerResponse404($event, Event\Type\Http\Response404::create()); }
/** * @return void */ public function init() { $this->addEventListener(Event\Type\Http\Request::toType(), function ($event) { if ($event->getPhase() == Event\PHASE_DOWN) { return $this->onBeforeExecution($event); } else { if ($event->getPhase() == Event\PHASE_UP) { return $this->onAfterExecution($event); } } }); }
/** * @return void */ public function init() { parent::init(); $this->addEventListener(Event\Type\Http\Request::toType(), function ($event) { $this->onHttpRequest($event); }); $this->addEventListener(Event\Type\Http\Response200::toType(), function ($event) { $requestEvent = $event->getLastDispatchedEvent(); $execResult = $requestEvent->getResult(); return $this->onResponse200($event, $execResult); }); $extendable = $this->getExtendableInstance(); if ($extendable) { $routeAnnot = $extendable->getRouteAnnotation(); $ctrlMethodAnnot = $extendable->getControllerMethodAnnotation(); $this->setControllerMethod($ctrlMethodAnnot->getMethodName()); $this->setAllowedHttpMethods($routeAnnot->getAllowedHttpMethods()); $this->setURIMatchRegExp($routeAnnot->getURIMatchRegExp()); $this->setURIMatchPattern($routeAnnot->getMatchPattern()); $validator = $this->instantiateValidator(); $this->setValidator($validator); } }
/** * @return bool */ public function process(Event\Type\Http\Request $event) { if (!$this->matchRequest($event->getRequest())) { return false; } $pkgActions = $this->getApplication()->getPackageActions($this->getPackage()); foreach ($pkgActions as $action) { if ($this->skipAction($action)) { continue; } if ($action->matchRequest($event->getRequest())) { $this->action = $action; $this->controller = $this->getFactory()->createControllerByAction($action); $this->frontController = $this->getFactory()->createFrontControllerByAction($action); return true; } } $this->triggerResponse404($event, Event\Type\Http\Response404::create()); return false; }