staticPath() public method

Get the static path portion for this route.
public staticPath ( ) : string
return string
Ejemplo n.º 1
0
 /**
  * Add a route to the collection.
  *
  * @param \Cake\Routing\Route\Route $route The route object to add.
  * @param array $options Additional options for the route. Primarily for the
  *   `_name` option, which enables named routes.
  * @return void
  */
 public function add(Route $route, array $options = [])
 {
     $this->_routes[] = $route;
     // Explicit names
     if (isset($options['_name'])) {
         $this->_named[$options['_name']] = $route;
     }
     // Generated names.
     $name = $route->getName();
     if (!isset($this->_routeTable[$name])) {
         $this->_routeTable[$name] = [];
     }
     $this->_routeTable[$name][] = $route;
     // Index path prefixes (for parsing)
     $path = $route->staticPath();
     if (empty($this->_paths[$path])) {
         $this->_paths[$path] = [];
         krsort($this->_paths);
     }
     $this->_paths[$path][] = $route;
     $extensions = $route->extensions();
     if ($extensions) {
         $this->extensions($extensions);
     }
 }
Ejemplo n.º 2
0
 /**
  * Add a route to the collection.
  *
  * @param \Cake\Routing\Route\Route $route The route object to add.
  * @param array $options Additional options for the route. Primarily for the
  *   `_name` option, which enables named routes.
  * @return void
  */
 public function add(Route $route, array $options = [])
 {
     $this->_routes[] = $route;
     // Explicit names
     if (isset($options['_name'])) {
         if (isset($this->_named[$options['_name']])) {
             $matched = $this->_named[$options['_name']];
             throw new DuplicateNamedRouteException(['name' => $options['_name'], 'url' => $matched->template, 'duplicate' => $matched]);
         }
         $this->_named[$options['_name']] = $route;
     }
     // Generated names.
     $name = $route->getName();
     if (!isset($this->_routeTable[$name])) {
         $this->_routeTable[$name] = [];
     }
     $this->_routeTable[$name][] = $route;
     // Index path prefixes (for parsing)
     $path = $route->staticPath();
     if (empty($this->_paths[$path])) {
         $this->_paths[$path] = [];
         krsort($this->_paths);
     }
     $this->_paths[$path][] = $route;
     $extensions = $route->getExtensions();
     if (count($extensions) > 0) {
         $this->extensions($extensions);
     }
 }
 /**
  * Test getting the static path for a route.
  *
  * @return void
  */
 public function testStaticPath()
 {
     $route = new Route('/*', ['controller' => 'Pages', 'action' => 'display']);
     $this->assertEquals('/', $route->staticPath());
     $route = new Route('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
     $this->assertEquals('/pages', $route->staticPath());
     $route = new Route('/pages/:id/*', ['controller' => 'Pages', 'action' => 'display']);
     $this->assertEquals('/pages/', $route->staticPath());
     $route = new Route('/:controller/:action/*');
     $this->assertEquals('/', $route->staticPath());
     $route = new Route('/books/reviews', ['controller' => 'Reviews', 'action' => 'index']);
     $this->assertEquals('/books/reviews', $route->staticPath());
 }