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
Fabien Potencier b912af9261 Merge branch '5.1'
* 5.1:
  Fix typo
  Fix deprecated libxml_disable_entity_loader
  Add Tagalog translations for validator messages 94, 95, 96 and 99
  PHPUnit's assertContains() performs strict comparisons now.
  [ClassLoader][Routing] Fix namespace parsing on php 8.
  Fix deprecated libxml_disable_entity_loader
  Made reference to PHPUnit\Util\XML::loadfile php5-compatible.
  [Validator] Add missing translations for german and vietnamese
  Modernized deprecated PHPUnit assertion calls
  [Console] The message of "class not found" errors has changed in php 8.
  The PHPUnit\Util\XML class has been removed in PHPUnit 9.3.
  [Console] Make sure we pass a numeric array of arguments to call_user_func_array().
  Remove outdated references from base_js.html.twig file
  [String] We cannot have a "provides" function in test cases.
  Typo: somes styles fixed
  [Serializer] Fix that it will never reach DOMNode
  [Validator] sync translations
  [VarDumper] Improve previous fix on light array coloration
  [Cache] Fix #37667
2020-08-10 10:10:48 +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 Merge branch '4.4' into 5.1 2020-08-10 10:03:57 +02:00
Matcher Merge branch '5.0' into 5.1 2020-06-18 20:24:02 +02:00
Tests [Router] allow to use \A and \z as regex start and end 2020-07-31 08:30:09 +02:00
.gitattributes add missing gitattributes for phpunit-bridge 2020-03-27 17:54:36 +01:00
.gitignore
CHANGELOG.md [Router] allow to use \A and \z as regex start and end 2020-07-31 08:30:09 +02:00
CompiledRoute.php Add return types to internal & magic methods when possible 2019-08-22 15:18:41 +02:00
composer.json Use ">=" for the "php" requirement 2020-07-05 11:39:30 +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 [Router] allow to use \A and \z as regex start and end 2020-07-31 08:30:09 +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