Beispiel #1
0
 /**
  * @param string $method
  * @param string $routeString
  *
  * @return void
  */
 private function setCurrentRequest(string $method, string $routeString)
 {
     $request = new Request();
     $request->setClientIp('127.0.0.1');
     $request->setMethod($method);
     $request->setQueryParams([]);
     $request->setRequestBody('');
     $request->setRouteStr($routeString);
     $request->setAjax(false);
     $request->setSecure(false);
     $property = new \ReflectionProperty(Request::class, 'currentRequest');
     $property->setAccessible(true);
     $property->setValue($request);
 }
Beispiel #2
0
 /**
  * Search for the route that matches the current
  * request. If not found, returns NULL.
  *
  * @return array|null
  */
 public static function getCurrentRoute()
 {
     $current = null;
     $request = Request::current();
     $routeStr = $request->getRouteStr();
     $method = $request->getMethod();
     //Search for the route
     foreach (self::$routes as $route) {
         //Check the method
         if (!in_array($method, $route['methods'])) {
             continue;
         }
         //Check number of slashes
         if (substr_count($route['route'], '/') != substr_count($routeStr, '/')) {
             continue;
         }
         //Checks the route string
         if (ParametrizedString::make($route['route'])->matches($routeStr)) {
             $current = $route;
             break;
         }
     }
     return $current;
 }
Beispiel #3
0
 /**
  * Creates a route that listens to all supported.
  *
  * @param string $routeStr
  * @param array  $info
  */
 public static function all(string $routeStr, array $info)
 {
     $methods = Request::getValidMethods();
     self::create($methods, $routeStr, $info);
 }
Beispiel #4
0
 /**
  * Capture the route string.
  *
  * @param Request $request
  */
 private static function fillCurrentRouteString(Request $request)
 {
     //Read data from $_SERVER array
     $requestUri = urldecode($_SERVER['REQUEST_URI']);
     $scriptName = $_SERVER['SCRIPT_NAME'];
     //Extract route string from the URI
     $length = strlen(dirname($scriptName));
     $routeAux = substr(explode('?', $requestUri)[0], $length);
     $route = '/';
     if ($routeAux && $routeAux != '/') {
         $route .= trim(str_replace('\\', '/', $routeAux), '/') . '/';
     }
     $request->setRouteStr($route);
 }
Beispiel #5
0
 /**
  * Load request parsers.
  */
 private function registerRequestParsers()
 {
     $parsers = $this->config('app')['requestParser'];
     foreach ($parsers as $parser) {
         Request::registerParser($parser);
     }
 }