Exemple #1
0
 /**
  * Execute a route and attempt to generate a response
  *
  * @param IRoute  $route
  * @param Request $request
  * @param int     $type
  * @param bool    $catch
  *
  * @return CubexResponse|null|Response
  * @throws \Exception
  */
 public function executeRoute(IRoute $route, Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $value = $route->getValue();
     $this->_processParams = $params = $route->getRouteData();
     //If the action has returned a valid response, lets send that back
     if ($value instanceof Response) {
         return $value;
     }
     //Attempt to see if the route is a callable
     if (is_callable($value)) {
         $value = $this->_getCallableResult($value, $params);
     } else {
         if (is_scalar($value)) {
             //If is fully qualified class, create class
             $match = '/^(\\\\?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)+$/';
             if (stripos($value, '\\') !== false && preg_match($match, $value)) {
                 $class = $value;
                 $nsClass = Path::buildWindows(Objects::getNamespace($this), $value);
                 try {
                     if (class_exists($nsClass)) {
                         $value = $this->getCubex()->make($nsClass);
                     } else {
                         $value = $this->getCubex()->make($class);
                     }
                 } catch (\Exception $e) {
                     if (!$catch) {
                         throw new \RuntimeException("Your route provides an invalid class '{$class}'");
                     } else {
                         return null;
                     }
                 }
             } else {
                 $call = $this->attemptCallable($value);
                 if ($call !== null) {
                     $value = $this->_getCallableResult($call, $params);
                 } else {
                     //Attempt to see if the route is a redirect
                     $url = $this->attemptUrl($value, $request);
                     if ($url !== null) {
                         //Redirect to url
                         return new RedirectResponse($url['url'], $url['code']);
                     } else {
                         //look for method names
                         $method = $this->attemptMethod($value, $request);
                         if ($method !== null) {
                             $value = $this->_getCallableResult([$this, $method], $params);
                         }
                     }
                 }
             }
         }
     }
     if ($value instanceof CubexKernel) {
         $value->_pathProcessed = Path::buildUnix($this->_pathProcessed, $route->getMatchedPath());
         $value->_processParams = $params;
     }
     return $this->_processResponse($value, $request, $type, $catch, $params);
 }
Exemple #2
0
 public function testBuildWindowsPath()
 {
     $this->assertEquals("a\\b", Path::buildWindows("a", "b"));
 }