Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on May 18, 2024 via composer

nikic/fast-route v1.3.0

Fast request router for PHP
Package summary
Share
0
issues
1
license
1
BSD-3-Clause
Package created
18 Feb 2014
Version published
13 Feb 2018
Maintainers
1
Total deps
1
Direct deps
0
License
BSD-3-Clause

Issues

0
This package has no issues

Licenses

BSD 3-Clause "New" or "Revised" License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
place-warranty
Cannot
use-trademark
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
nikic/fast-route@v1.3.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of nikic/fast-route 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does nikic/fast-route do?

nikic/fast-route is an open-source PHP library that provides a fast implementation of a regular expression-based router. It helps in routing HTTP requests to specific handle callbacks based on the request methods and URI patterns. The router allows you to define sophisticated routing patterns with placeholder and optional segments, handle common request methods, and also supports route grouping for better organization and controlled routing. Additionally, nikic/fast-route offers features such as route data caching for enhanced performance and also supports overwriting the route parser and dispatcher for greater customization.

How do you use nikic/fast-route?

To use nikic/fast-route, start by installing the package with Composer by running the command composer require nikic/fast-route. After installation, you can load the library through Composer's autoloader and use it in your PHP application. A simple example of using nikic/fast-route would look like this:

<?php

require '/path/to/vendor/autoload.php';

$dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) {
    $r->addRoute('GET', '/users', 'get_all_users_handler');
    $r->addRoute('GET', '/user/{id:\d+}', 'get_user_handler');
    $r->addRoute('GET', '/articles/{id:\d+}[/{title}]', 'get_article_handler');
});

$httpMethod = $_SERVER['REQUEST_METHOD'];
$uri = $_SERVER['REQUEST_URI'];

if (false !== $pos = strpos($uri, '?')) {
    $uri = substr($uri, 0, $pos);
}
$uri = rawurldecode($uri);

$routeInfo = $dispatcher->dispatch($httpMethod, $uri);
switch ($routeInfo[0]) {
    case FastRoute\Dispatcher::NOT_FOUND:
        // ... 404 Not Found
        break;
    case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
        $allowedMethods = $routeInfo[1];
        // ... 405 Method Not Allowed
        break;
    case FastRoute\Dispatcher::FOUND:
        $handler = $routeInfo[1];
        $vars = $routeInfo[2];
        // ... call $handler with $vars
        break;
}

The routes are defined within the simpleDispatcher() function, and you can specify different HTTP methods, URIs, and handlers for the different routes. The library will then match the current HTTP request method and URI to the defined routes and call the appropriate handler.

Where are the nikic/fast-route docs?

The nikic/fast-route documentation is included in the README file on the project's GitHub repository, available at https://github.com/nikic/FastRoute. The documentation provides an informative guide on the usage of the library with various examples on defining routes, handling different HTTP methods, using route groups and caching, and also overwriting custom route parsers and dispatchers.