Cake\Routing\Route\Route::extensions PHP Method

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.
    public function extensions($extensions = null)
    {
        if ($extensions === null) {
            return $this->_extensions;
        }
        $this->_extensions = (array) $extensions;
    }

Usage Example

 /**
  * 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']);
 }
All Usage Examples Of Cake\Routing\Route\Route::extensions