This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Routing
Nicolas Grekas 143718c750 Merge branch '3.4' into 4.4
* 3.4:
  Fix abstract method name in PHP doc block
2020-05-30 22:07:26 +02:00
..
Annotation [Routing] Remove unused properties from the Route annotation 2020-04-20 16:41:27 +02:00
DependencyInjection Merge branch '3.4' into 4.1 2019-01-16 19:21:11 +01:00
Exception Allow \Throwable $previous everywhere 2019-11-12 15:51:11 +01:00
Generator Merge branch '4.3' into 4.4 2020-01-04 14:00:46 +01:00
Loader Merge branch '3.4' into 4.4 2020-05-30 22:07:26 +02:00
Matcher Fixed some typos 2020-03-25 13:02:26 +01:00
Tests [Routing] Add missing _locale requirements 2020-04-20 14:17:53 +02:00
.gitattributes add missing gitattributes for phpunit-bridge 2020-03-27 17:54:36 +01:00
.gitignore
CHANGELOG.md [Routing][Config] Allow patterns of resources to be excluded from config loading 2019-10-24 13:56:35 +02:00
CompiledRoute.php Add return types to internal & magic methods when possible 2019-08-22 15:18:41 +02:00
composer.json Allow Symfony 5.0 2019-05-28 17:53:17 +02:00
LICENSE Update year in license files 2020-01-01 12:03:25 +01:00
phpunit.xml.dist Bump phpunit XSD version to 5.2 2018-11-11 12:18:13 +01:00
README.md Add installation and minimal example to README 2020-03-28 12:43:28 +01:00
RequestContext.php Merge branch '3.4' into 4.3 2019-11-30 14:16:45 +01:00
RequestContextAwareInterface.php [DI] minor docblock fixes 2017-10-24 13:40:19 +02:00
Route.php [Routing] Prevent localized routes _locale default & requirement from being overridden 2020-03-02 17:08:48 +01:00
RouteCollection.php cleanup remaining param and internal Intl FulLTransformer 2019-08-08 16:35:53 +02:00
RouteCollectionBuilder.php Merge branch '3.4' into 4.3 2019-08-14 14:26:46 +02:00
RouteCompiler.php Merge branch '3.4' into 4.4 2020-03-16 09:56:54 +01:00
RouteCompilerInterface.php [DI] minor docblock fixes 2017-10-24 13:40:19 +02:00
Router.php Merge branch '4.3' into 4.4 2020-01-08 18:29:02 +01:00
RouterInterface.php [Routing] added a warning about the getRouteCollection() method 2019-08-04 04:46:49 +02:00

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