public function register($rtPath, $callback, $rtHandle = null, $additionalAttributes = array())
 {
     // setup up standard concrete5 routing.
     $rtPathTrimmed = trim($rtPath, '/');
     if (!$rtHandle) {
         $rtHandle = preg_replace('/[^A-Za-z0-9\\_]/', '_', $rtPathTrimmed);
         $rtHandle = preg_replace('/\\_+/', '_', $rtHandle);
         $rtHandle = trim($rtHandle, '_');
     }
     $rtPath = '/' . $rtPathTrimmed . '/';
     $attributes = array();
     if ($callback instanceof \Closure) {
         $attributes = ClosureRouteCallback::getRouteAttributes($callback);
     } else {
         if ($callback == 'dispatcher') {
             $attributes = DispatcherRouteCallback::getRouteAttributes($callback);
         } else {
             $attributes = ControllerRouteCallback::getRouteAttributes($callback);
         }
     }
     $attributes['path'] = $rtPath;
     $route = new Route($rtPath, $attributes, $additionalAttributes);
     $this->collection->add($rtHandle, $route);
 }
Exemple #2
0
 /**
  * Inspects the request and determines what to serve.
  */
 public function dispatch(Request $request)
 {
     // This is a crappy place for this, but it has to come AFTER the packages because sometimes packages
     // want to replace legacy "tools" URLs with the new MVC, and the tools paths are so greedy they don't
     // work unless they come at the end.
     $this->registerLegacyRoutes();
     $path = rawurldecode($request->getPathInfo());
     if (substr($path, 0, 3) == '../' || substr($path, -3) == '/..' || strpos($path, '/../') || substr($path, 0, 3) == '..\\' || substr($path, -3) == '\\..' || strpos($path, '\\..\\')) {
         throw new \RuntimeException(t('Invalid path traversal. Please make this request with a valid HTTP client.'));
     }
     if ($this->installed) {
         $response = $this->getEarlyDispatchResponse();
     }
     if (!isset($response)) {
         $collection = Route::getList();
         $context = new \Symfony\Component\Routing\RequestContext();
         $context->fromRequest($request);
         $matcher = new UrlMatcher($collection, $context);
         $path = rtrim($request->getPathInfo(), '/') . '/';
         try {
             $request->attributes->add($matcher->match($path));
             $matched = $matcher->match($path);
             $route = $collection->get($matched['_route']);
             Route::setRequest($request);
             $response = Route::execute($route, $matched);
         } catch (ResourceNotFoundException $e) {
             $callback = new DispatcherRouteCallback('dispatcher');
             $response = $callback->execute($request);
         }
     }
     return $response;
 }
Exemple #3
0
 /**
  * Inspects the request and determines what to serve.
  */
 public function dispatch(Request $request)
 {
     if ($this->installed) {
         $response = $this->getEarlyDispatchResponse();
     }
     if (!isset($response)) {
         $collection = Route::getList();
         $context = new \Symfony\Component\Routing\RequestContext();
         $context->fromRequest($request);
         $matcher = new UrlMatcher($collection, $context);
         $path = rtrim($request->getPathInfo(), '/') . '/';
         try {
             $request->attributes->add($matcher->match($path));
             $matched = $matcher->match($path);
             $route = $collection->get($matched['_route']);
             Route::setRequest($request);
             $response = Route::execute($route, $matched);
         } catch (ResourceNotFoundException $e) {
             $callback = new DispatcherRouteCallback('dispatcher');
             $response = $callback->execute($request);
         }
     }
     return $response;
 }
Exemple #4
0
 /**
  * Register a symfony route with as little as a path and a callback.
  *
  * @param string $path The full path for the route
  * @param \Closure|string $callback `\Closure` or "dispatcher" or "\Namespace\Controller::action_method"
  * @param string|null $handle The route handle, if one is not provided the handle is generated from the path "/" => "_"
  * @param array $requirements The Parameter requirements, see Symfony Route constructor
  * @param array $options The route options, see Symfony Route constructor
  * @param string $host The host pattern this route requires, see Symfony Route constructor
  * @param array|string $schemes The schemes or scheme this route requires, see Symfony Route constructor
  * @param array|string $methods The HTTP methods this route requires, see see Symfony Route constructor
  * @param string $condition see Symfony Route constructor
  * @return \Symfony\Component\Routing\Route
  */
 public function register($path, $callback, $handle = null, array $requirements = array(), array $options = array(), $host = '', $schemes = array(), $methods = array(), $condition = null)
 {
     // setup up standard concrete5 routing.
     $trimmed_path = trim($path, '/');
     if (!$handle) {
         $handle = preg_replace('/[^A-Za-z0-9\\_]/', '_', $trimmed_path);
         $handle = preg_replace('/\\_+/', '_', $handle);
         $handle = trim($handle, '_');
     }
     $path = '/' . $trimmed_path . '/';
     if ($callback instanceof \Closure) {
         $attributes = ClosureRouteCallback::getRouteAttributes($callback);
     } else {
         if ($callback == 'dispatcher') {
             $attributes = DispatcherRouteCallback::getRouteAttributes($callback);
         } else {
             $attributes = ControllerRouteCallback::getRouteAttributes($callback);
         }
     }
     $attributes['path'] = $path;
     $route = new Route($path, $attributes, $requirements, $options, $host, $schemes, $methods, $condition);
     $this->collection->add($handle, $route);
     return $route;
 }