Routing - The Routing component maps an HTTP request to a set of configuration variables.

Overview

Routing Component

The Routing component maps an HTTP request to a set of configuration variables.

Getting Started

$ composer require symfony/routing
use App\Controller\BlogController;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

$route = new Route('/blog/{slug}', ['_controller' => BlogController::class]);
$routes = new RouteCollection();
$routes->add('blog_show', $route);

$context = new RequestContext();

// Routing can match routes with incoming requests
$matcher = new UrlMatcher($routes, $context);
$parameters = $matcher->match('/blog/lorem-ipsum');
// $parameters = [
//     '_controller' => 'App\Controller\BlogController',
//     'slug' => 'lorem-ipsum',
//     '_route' => 'blog_show'
// ]

// Routing can also generate URLs for a given route
$generator = new UrlGenerator($routes, $context);
$url = $generator->generate('blog_show', [
    'slug' => 'my-blog-post',
]);
// $url = '/blog/my-blog-post'

Resources

You might also like...
PhpRouter is a powerful, lightweight, and very fast HTTP URL router for PHP projects.

PhpRouter PhpRouter is a powerful, lightweight, and very fast HTTP URL router for PHP projects. Some of the provided features: Route parameters Predef

A router for Amp's HTTP Server.

http-server-router This package provides a routing RequestHandler for Amp's HTTP server based on the request URI and method based on FastRoute. Instal

Preferences are configuration variables that are user-managed for which we cannot rely upon container parameters or environment variables.

Preferences Preferences are configuration variables that are meant to be user managed for which we cannot rely upon container parameters or environmen

HTTP Requestor: Package for a client request that supports you to make an external service request easily and with fast usage.

HttpRequestor from Patienceman HTTP Requestor: Package for a client request that supports you to make an external service request easily and with fast

Csrf Component provides Cross Site Request Forgery protection by comparing provided token with session token to ensure request validity.

Csrf Component Csrf Component provides Cross Site Request Forgery protection by comparing provided token with session token to ensure request validity

Http-kernel - The HttpKernel component provides a structured process for converting a Request into a Response.

HttpKernel Component The HttpKernel component provides a structured process for converting a Request into a Response by making use of the EventDispatc

PHP routing class. Lightweight yet flexible. Supports REST, dynamic and reversed routing.

AltoRouter AltoRouter is a small but powerful routing class, heavily inspired by klein.php. $router = new AltoRouter(); // map homepage $router-map(

Map request on your DTO object with zero configuration.
Map request on your DTO object with zero configuration.

Map request on your DTO object with zero configuration. Install composer require prugala/symfony-request-dto Usage Create a DTO that implements the in

This Package helps you in laravel application to log all desired activity for each request from request entry point to generate response at a single snapshot.

Laravel Scenario Logger This Package helps you in laravel application to log all desired activity for each request from request entry point to generat

GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.
GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.

GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.

Fast PSR-7 based routing and dispatch component including PSR-15 middleware, built on top of FastRoute.

Route This package is compliant with PSR-1, PSR-2, PSR-4, PSR-7, PSR-11 and PSR-15. If you notice compliance oversights, please send a patch via pull

Laravel Livewire full page component routing.

Laravel Livewire Routes Laravel Livewire full page component routing. This package allows you to specify routes directly inside your full page Livewir

Abstracts HTTP request input handling, providing an easy interface for data hydration and validation

Linio Input Linio Input is yet another component of the Linio Framework. It aims to abstract HTTP request input handling, allowing a seamless integrat

It validates PSR-7 messages (HTTP request/response) against OpenAPI specifications
It validates PSR-7 messages (HTTP request/response) against OpenAPI specifications

NOTICE - THE PACKAGE HAS BEEN CONTRIBUTED TO THE PHP LEAGUE Go to https://github.com/thephpleague/openapi-psr7-validator This package is here for exis

Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

 Laravel Logable is a simple way to log http request in your Laravel application.
Laravel Logable is a simple way to log http request in your Laravel application.

Laravel Logable is a simple way to log http request in your Laravel application. Requirements php = 7.4 Laravel version = 6.0 Installation composer

It validates PSR-7 messages (HTTP request/response) against OpenAPI specifications
It validates PSR-7 messages (HTTP request/response) against OpenAPI specifications

OpenAPI PSR-7 Message (HTTP Request/Response) Validator This package can validate PSR-7 messages against OpenAPI (3.0.x) specifications expressed in Y

Security CSRF (cross-site request forgery) component provides a class CsrfTokenManager for generating and validating CSRF tokens.

Security Component - CSRF The Security CSRF (cross-site request forgery) component provides a class CsrfTokenManager for generating and validating CSR

Comments
  • enable extensibility of options

    enable extensibility of options

    Currently, if you write your own SymfonyFrameworkBundle using the main Symfony Components, it is not possible to extend the options of the router without overwriting the complete setOptions()-Methode.

    opened by ck-1 1
  • Bugfix: New syntax of named subpatterns (regex) are only supported by PCRE 7.0

    Bugfix: New syntax of named subpatterns (regex) are only supported by PCRE 7.0

    This push request fixed problems in the Route compiler that uses named subpatterns syntax that is only supported by PCRE 7.0 and above. Some PHP versions (also PHP 5.3 on CentOS) are compiled against PCRE 6.6 and lower. The named subpattern syntax that is used ('?<....>') was replaced with the backward compartible syntax ('?P<.....>').

    • Changed named subpattern syntax from '?<....>' to '?P<.....>'
    • Updated unit tests and fixtures

    BTW: The error was found by deploying the latest version of silex in production.

    opened by dol 1
  • The 'config' variable is already used as an array expression less...

    The 'config' variable is already used as an array expression less...

    The 'config' variable is already used as an array expression less...

    Using a variable both as an 'array expression' and as a 'key' or 'value' most often is a typing error.

    opened by tecnocat 0
Releases(v6.2.3)
  • v6.2.3(Dec 28, 2022)

  • v6.1.9(Dec 28, 2022)

  • v6.0.17(Dec 28, 2022)

  • v5.4.17(Dec 28, 2022)

  • v6.2.0(Nov 30, 2022)

  • v6.2.0-RC1(Nov 25, 2022)

  • v6.2.0-BETA3(Nov 19, 2022)

    Changelog (https://github.com/symfony/routing/compare/v6.2.0-BETA2...v6.2.0-BETA3)

    • bug #48170 Fix PSR-4 directory loader for abstract classes (derrabus)
    Source code(tar.gz)
    Source code(zip)
  • v6.2.0-BETA2(Oct 28, 2022)

  • v6.1.7(Oct 28, 2022)

    Changelog (https://github.com/symfony/routing/compare/v6.1.6...v6.1.7)

    • bug #47855 TypeError in Router when using UrlGenerator (Maximilian.Beckers)
    Source code(tar.gz)
    Source code(zip)
  • v6.0.15(Oct 28, 2022)

    Changelog (https://github.com/symfony/routing/compare/v6.0.14...v6.0.15)

    • bug #47855 TypeError in Router when using UrlGenerator (Maximilian.Beckers)
    Source code(tar.gz)
    Source code(zip)
  • v5.4.15(Oct 28, 2022)

    Changelog (https://github.com/symfony/routing/compare/v5.4.14...v5.4.15)

    • bug #47855 TypeError in Router when using UrlGenerator (Maximilian.Beckers)
    Source code(tar.gz)
    Source code(zip)
  • v6.2.0-BETA1(Oct 24, 2022)

    Changelog (https://github.com/symfony/routing/compare/v6.1.6...v6.2.0-BETA1)

    • feature #47943 Nicer config syntax for PSR-4 route loading (derrabus)
    • feature #47916 PSR-4 directory loader (derrabus)
    • feature #47525 Add UuidV7 and UuidV8 (nicolas-grekas)
    • feature #46430 Add Requirement::POSITIVE_INT for common ids and pagination (HeahDude)
    Source code(tar.gz)
    Source code(zip)
  • v6.1.5(Sep 30, 2022)

  • v6.1.3(Jul 29, 2022)

  • v6.0.11(Jul 29, 2022)

  • v5.4.11(Jul 29, 2022)

  • v4.4.44(Jul 29, 2022)

  • v6.1.1(Jun 9, 2022)

  • v6.1.0(May 27, 2022)

  • v6.1.0-RC1(May 14, 2022)

  • v6.1.0-BETA2(Apr 27, 2022)

    Changelog (https://github.com/symfony/routing/compare/v6.1.0-BETA1...v6.1.0-BETA2)

    • feature #46157 Remove variadic constructor signature (wouterj)
    • feature #46042 Add params variable to condition expression (HypeMC)
    • bug #46097 fix router base url when default uri has trailing slash (Tobion)
    • feature #45528 Add Requirement, a collection of universal regular-expressions constants to use as route parameter requirements (fancyweb)
    Source code(tar.gz)
    Source code(zip)
  • v6.0.8(Apr 27, 2022)

    Changelog (https://github.com/symfony/routing/compare/v6.0.7...v6.0.8)

    • bug #46097 fix router base url when default uri has trailing slash (Tobion)
    Source code(tar.gz)
    Source code(zip)
  • v5.4.8(Apr 27, 2022)

    Changelog (https://github.com/symfony/routing/compare/v5.4.7...v5.4.8)

    • bug #46097 fix router base url when default uri has trailing slash (Tobion)
    Source code(tar.gz)
    Source code(zip)
  • v4.4.41(Apr 27, 2022)

  • v6.1.0-BETA1(Apr 15, 2022)

    Changelog (https://github.com/symfony/routing/compare/v6.0.7...v6.1.0-BETA1)

    • feature #45803 Add EnumRequirement to help generate route requirements from a \BackedEnum (fancyweb)
    • feature #45658 Avoid double encoded slashes in query parameters (usu)
    • feature #45377 Bump minimum version of PHP to 8.1 (nicolas-grekas)
    • feature #44615 Support the "attribute" type (alias of "annotation") in annotation loaders (fancyweb)
    • feature #45075 Enrich MissingMandatoryParametersException (adrienlucas)
    • feature #45054 Allow using UTF-8 parameter names (nicolas-grekas)
    Source code(tar.gz)
    Source code(zip)
  • v6.0.5(Feb 28, 2022)

    Changelog (https://github.com/symfony/routing/compare/v6.0.4...v6.0.5)

    • bug #45263 AnnotationDirectoryLoader::load() may return null (mhujer)
    Source code(tar.gz)
    Source code(zip)
  • v6.0.3(Jan 28, 2022)

  • v5.4.3(Jan 28, 2022)

  • v5.3.14(Jan 28, 2022)

  • v4.4.37(Jan 28, 2022)

Fast PSR-7 based routing and dispatch component including PSR-15 middleware, built on top of FastRoute.

Route This package is compliant with PSR-1, PSR-2, PSR-4, PSR-7, PSR-11 and PSR-15. If you notice compliance oversights, please send a patch via pull

The League of Extraordinary Packages 608 Dec 30, 2022
Generate a PHP script for faster routing :rocket:

SwitchRoute Generating a PHP script for faster routing. The traditional way of routing uses regular expressions. This method was improved by FastRoute

Arnold Daniels 75 Nov 20, 2022
Convention based routing for PHP

Croute Convention based routing for PHP based on Symfony components. Croute is great because: You don't need to maintain a routing table Promotes cons

Michael O'Connell 12 Nov 9, 2021
PHP routing (like laravel) (not complete yet)

PHP Router (under construction) This repository contains routing classes that enables you to define your routes similar to laravel 8 routes. Features

Kareem M. Fouad 6 Jan 16, 2022
Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.

The PHP HTTP Flight Router divineniiquaye/flight-routing is a HTTP router for PHP 7.1+ based on PSR-7 and PSR-15 with support for annotations, created

Divine Niiquaye Ibok 16 Nov 1, 2022
Ertuo: quick routing for PHP

Ertuo: quick routing for PHP Ertuo (anagram of "Route"), is a small PHP library that does routing better and faster than conventional regular expressi

Ertuo 29 Jul 19, 2022
PHPRouter is an easy-to-use, fast, and flexible PHP router package with express-style routing.

PHP-Router is a modern, fast, and adaptable composer package that provides express-style routing in PHP without a framework.

Ayodeji O. 4 Oct 20, 2022
🔍 This is a collection of utilities for routing and loading components.

Router Utilities - PHP Introduction A day will come when I will write documentation for this library. Until then, you can use this library to create r

Utilities for PHP 5 Sep 20, 2022
Fast request router for PHP

FastRoute - Fast request router for PHP This library provides a fast implementation of a regular expression based router. Blog post explaining how the

Nikita Popov 4.7k Dec 23, 2022
:tada: Release 2.0 is released! Very fast HTTP router for PHP 7.1+ (incl. PHP8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger)

HTTP router for PHP 7.1+ (incl. PHP 8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger) Installation compo

Sunrise // PHP 151 Jan 5, 2023