extensions() public method

Get/Set the supported extensions for this route.
Deprecation: 3.3.9 Use getExtensions/setExtensions instead.
public extensions ( null | string | array $extensions = null ) : array | null
$extensions null | string | array The extensions to set. Use null to get.
return array | null The extensions or null.
 /**
  * Test parsing routes with extensions.
  *
  * @return void
  */
 public function testRouteParsingWithExtensions()
 {
     $route = new Route('/:controller/:action/*', [], ['_ext' => ['json', 'xml']]);
     $result = $route->parse('/posts/index');
     $this->assertFalse(isset($result['_ext']));
     $result = $route->parse('/posts/index.pdf');
     $this->assertFalse(isset($result['_ext']));
     $route->extensions(['pdf', 'json', 'xml']);
     $result = $route->parse('/posts/index.pdf');
     $this->assertEquals('pdf', $result['_ext']);
     $result = $route->parse('/posts/index.json');
     $this->assertEquals('json', $result['_ext']);
     $result = $route->parse('/posts/index.xml');
     $this->assertEquals('xml', $result['_ext']);
 }
Example #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'])) {
         $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);
     }
 }