From 0a1badfb592177c2d0530aff89c5d3a4225078cf Mon Sep 17 00:00:00 2001 From: Andrey Bolonin Date: Sun, 19 Aug 2018 10:58:47 +0300 Subject: [PATCH 1/2] Update routing.rst --- components/routing.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/components/routing.rst b/components/routing.rst index 7bccb0e0a47..cdd7dc6ae10 100644 --- a/components/routing.rst +++ b/components/routing.rst @@ -255,6 +255,28 @@ out here. .. include:: /_includes/_annotation_loader_tip.rst.inc +Some final example to use routes as annotations:: + + \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']); + + use Symfony\Component\Routing\Matcher\UrlMatcher; + use Symfony\Component\Routing\RequestContext; + + $loader = new \Symfony\Component\Routing\Loader\AnnotationDirectoryLoader( + new \Symfony\Component\Config\FileLocator(__DIR__.'/app/controllers/'), + new \Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader( + new \Doctrine\Common\Annotations\AnnotationReader() + ) + ); + + $routes = $loader->load(__DIR__.'/app/controllers/'); + + $context = new RequestContext('/'); + + $matcher = new UrlMatcher($routes, $context); + + $parameters = $matcher->match($_SERVER['REQUEST_URI']); + The all-in-one Router ~~~~~~~~~~~~~~~~~~~~~ From 54743d63d7e18cb1906f0e575294fffc1589b55d Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Tue, 28 Aug 2018 14:58:06 -0400 Subject: [PATCH 2/2] cleaning up some use statements, etc --- components/routing.rst | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/components/routing.rst b/components/routing.rst index cdd7dc6ae10..5977e1c498a 100644 --- a/components/routing.rst +++ b/components/routing.rst @@ -250,32 +250,24 @@ Annotation Routing Loaders Last but not least there are :class:`Symfony\\Component\\Routing\\Loader\\AnnotationDirectoryLoader` and :class:`Symfony\\Component\\Routing\\Loader\\AnnotationFileLoader` to load -route definitions from class annotations. The specific details are left -out here. +route definitions from class annotations:: -.. include:: /_includes/_annotation_loader_tip.rst.inc - -Some final example to use routes as annotations:: - - \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']); - - use Symfony\Component\Routing\Matcher\UrlMatcher; - use Symfony\Component\Routing\RequestContext; + use Doctrine\Common\Annotations\AnnotationReader; + use Symfony\Component\Config\FileLocator; + use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader; + use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader; - $loader = new \Symfony\Component\Routing\Loader\AnnotationDirectoryLoader( - new \Symfony\Component\Config\FileLocator(__DIR__.'/app/controllers/'), - new \Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader( - new \Doctrine\Common\Annotations\AnnotationReader() + $loader = new AnnotationDirectoryLoader( + new FileLocator(__DIR__.'/app/controllers/'), + new AnnotatedRouteControllerLoader( + new AnnotationReader() ) ); $routes = $loader->load(__DIR__.'/app/controllers/'); + // ... - $context = new RequestContext('/'); - - $matcher = new UrlMatcher($routes, $context); - - $parameters = $matcher->match($_SERVER['REQUEST_URI']); +.. include:: /_includes/_annotation_loader_tip.rst.inc The all-in-one Router ~~~~~~~~~~~~~~~~~~~~~