getRequest() public method

public getRequest ( ) : Request
return Coduo\TuTu\Config\Element\Request
Esempio n. 1
0
 /**
  * @param Request $request
  * @param Element $config
  * @return bool
  */
 public function match(Request $request, Element $config)
 {
     if (!count($config->getRequest()->getAllowedMethods())) {
         return true;
     }
     return in_array($request->getMethod(), $config->getRequest()->getAllowedMethods(), true);
 }
Esempio n. 2
0
 /**
  * @param Request $request
  * @param Element $config
  * @return boolean
  */
 public function match(Request $request, Element $config)
 {
     if (!$config->getRequest()->hasBody()) {
         return true;
     }
     if (!$this->phpMatcher->match($request->getContent(), $config->getRequest()->getBody())) {
         return false;
     }
     return true;
 }
Esempio n. 3
0
 /**
  * @param Request $request
  * @param Element $config
  * @return bool
  */
 public function match(Request $request, Element $config)
 {
     $pathPattern = $config->getRequest()->getPath();
     preg_match_all('#\\{\\w+\\}#', $config->getRequest()->getPath(), $placeholders, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
     foreach ($placeholders as $placeholderMatch) {
         $placeholder = $placeholderMatch[0][0];
         $pathPattern = str_replace($placeholder, '__PLACEHOLDER__', $pathPattern);
     }
     $pathPattern = '/^' . str_replace('__PLACEHOLDER__', '([^\\/]*)', preg_quote($pathPattern, '/')) . '$/i';
     return 0 !== preg_match($pathPattern, $request->getPathInfo());
 }
Esempio n. 4
0
 /**
  * @param Request $request
  * @param Element $config
  * @return boolean
  */
 public function match(Request $request, Element $config)
 {
     if (!$config->getRequest()->hasHeaders()) {
         return true;
     }
     foreach ($config->getRequest()->getHeaders() as $headerName => $headerValuePattern) {
         if (!$request->headers->has($headerName)) {
             return false;
         }
         if (!$this->phpMatcher->match($request->headers->get($headerName), $headerValuePattern)) {
             return false;
         }
     }
     return true;
 }
Esempio n. 5
0
 /**
  * @param Request $request
  * @param Element $config
  * @return boolean
  */
 public function match(Request $request, Element $config)
 {
     if (!$config->getRequest()->hasBodyParameters() && !$config->getRequest()->hasQueryParameters()) {
         return true;
     }
     foreach ($config->getRequest()->getQueryParameters() as $name => $valuePattern) {
         if (!$request->query->has($name)) {
             return false;
         }
         if (!$this->phpMatcher->match($request->query->get($name), $valuePattern)) {
             return false;
         }
     }
     foreach ($config->getRequest()->getBodyParameters() as $name => $valuePattern) {
         if (!$request->request->has($name)) {
             return false;
         }
         if (!$this->phpMatcher->match($request->request->get($name), $valuePattern)) {
             return false;
         }
     }
     return true;
 }
Esempio n. 6
0
 /**
  * @param Element $config
  * @param Request $request
  * @return Response
  */
 public function build(Element $config, Request $request)
 {
     $content = $this->twig->render($config->getResponse()->getContent(), ['request' => $request, 'path' => $this->requestParser->extractPlaceholders($request, $config->getRequest()->getPath())]);
     return new Response($content, $config->getResponse()->getStatus(), $config->getResponse()->getHeaders());
 }