示例#1
0
 /**
  * @return boolean
  */
 protected final function matchRequest(Request $request)
 {
     $match = false;
     if (!empty($this->hostname) && $this->hostname == $request->getHostname()) {
         $match = true;
     }
     if (!empty($this->uriPathPrefix)) {
         $match = strpos($request->getUri()->getPath(), $this->uriPathPrefix) === 0 ? true : false;
     }
     if ($match) {
         $this->isActive = true;
     }
     return $match;
 }
示例#2
0
 protected function makeRequest($reqBodyFilename, &$requestEvent = null)
 {
     $request = Request::createFromFile($reqBodyFilename);
     $requestEvent = new RequestEvent();
     $requestEvent->setRequest($request);
     $internalEvent = $this->appPkg->dispatch($requestEvent);
     return $internalEvent;
 }
示例#3
0
 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;
 }
示例#4
0
 /**
  * @return boolean
  */
 public function matchRequest(Request $request)
 {
     $allowedMethods = $this->getAllowedHttpMethods();
     if (!empty($allowedMethods) && !in_array($request->getMethod(), $allowedMethods)) {
         return false;
     }
     $regExp = $this->getURIMatchRegExp();
     if (!empty($regExp)) {
         $matches = null;
         if (!$request->getUri()->matchUriPath($regExp, $matches)) {
             return false;
         }
         // Fill the URI input container with pattern matches
         array_shift($matches);
         $tmpArray = [];
         foreach ($matches as $itemKey => $itemValue) {
             if (is_integer($itemKey)) {
                 continue;
             }
             $tmpArray[$itemKey] = $itemValue;
         }
         $uriInput = $this->getApplication()->getRequest()->getURIInput();
         $uriInput->merge(Input::create($tmpArray));
         // set default placeholder value
         $routeAnnot = $this->getExtendableInstance()->getRouteAnnotation();
         if ($routeAnnot->hasDefaultItemValue()) {
             $itemValue = isset($matches[1]) ? $matches[1] : $routeAnnot->getDefaultItemValue();
             $uriInput->set($routeAnnot->getDefaultItemKey(), $itemValue);
         }
         return true;
     } else {
         return false;
     }
 }
示例#5
0
 /**
  * @return void
  */
 public function setAllowedHttpMethods($mixed)
 {
     if ('ALL' == $mixed) {
         return;
     } else {
         if (is_string($mixed)) {
             $parts = explode('|', $mixed);
             foreach ($parts as $methodName) {
                 if (!in_array($methodName, Request::getKnownHttpMethods())) {
                     FrameworkRuntimeError::create('Unknown HTTP method "%s"', null, $methodName)->_throw();
                 }
                 $this->allowedHttpMethods[] = $methodName;
             }
         } else {
             $this->allowedHttpMethods = $mixed;
         }
     }
 }
示例#6
0
 /**
  * @return $this
  */
 public static function create(...$args)
 {
     $event = new static();
     $event->httpRequest = HttpRequest::createFromGlobals();
     return $event;
 }