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 2121c55b02 Merge branch '5.0' into 5.1
* 5.0:
  [VarDumper] fix typo
  Fix support for PHP8 union types
  [FrameworkBundle] preserve dots in query-string when redirecting
  [3.4] Fix support for PHP8 union types
  [PhpUnitBridge] Streamline ansi/no-ansi of composer according to phpunit --colors option
  [3.4] Small update in our internal terminology
  [Cache] fix compat with DBAL v3
  [HttpClient] Convert CurlHttpClient::handlePush() to instance method
  [VarDumper] Fix CliDumper coloration
  [DI] tighten detection of local dirs to prevent false positives
  [FrameworkBundle] preserve dots in query-string when redirecting
  Fix precendence in 4.4
  bumped Symfony version to 3.4.43
  updated VERSION for 3.4.42
  update CONTRIBUTORS for 3.4.42
  updated CHANGELOG for 3.4.42
2020-06-18 20:24:02 +02:00
..
Annotation Merge branch '5.0' 2020-04-21 23:06:40 +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.4' into 5.0 2020-01-04 15:08:26 +01:00
Loader kept routes priorities after add a name prefix to the collection 2020-06-10 07:49:58 -04:00
Matcher Merge branch '5.0' into 5.1 2020-06-18 20:24:02 +02:00
Tests kept routes priorities after add a name prefix to the collection 2020-06-10 07:49:58 -04:00
.gitattributes add missing gitattributes for phpunit-bridge 2020-03-27 17:54:36 +01:00
.gitignore
CHANGELOG.md [FrameworkBundle] Allow configuring the default base URI with a DSN 2020-05-04 09:14:05 +02:00
CompiledRoute.php Add return types to internal & magic methods when possible 2019-08-22 15:18:41 +02:00
composer.json Merge branch '5.0' into 5.1 2020-05-20 19:43:50 +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 [FrameworkBundle] use the router context by default for assets 2020-05-04 10:37:33 +02:00
RequestContextAwareInterface.php [DI] minor docblock fixes 2017-10-24 13:40:19 +02:00
Route.php fix merge (bis) 2020-04-21 23:40:12 +02:00
RouteCollection.php kept routes priorities after add a name prefix to the collection 2020-06-10 07:49:58 -04:00
RouteCollectionBuilder.php Leverage trigger_deprecation() from symfony/deprecation-contracts 2020-02-08 15:04:50 +01:00
RouteCompiler.php fix merge (bis) 2020-04-21 23:40:12 +02: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