8000 Update routing.rst · symfony/symfony-docs@0a1badf · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a1badf

Browse files
andreyboloninjaviereguiluz
authored andcommitted
Update routing.rst
1 parent 076478c commit 0a1badf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

components/routing.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,28 @@ out here.
255255

256256
.. include:: /_includes/_annotation_loader_tip.rst.inc
257257

258+
Some final example to use routes as annotations::
259+
260+
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']);
261+
262+
use Symfony\Component\Routing\Matcher\UrlMatcher;
263+
use Symfony\Component\Routing\RequestContext;
264+
265+
$loader = new \Symfony\Component\Routing\Loader\AnnotationDirectoryLoader(
266+
new \Symfony\Component\Config\FileLocator(__DIR__.'/app/controllers/'),
267+
new \Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader(
268+
new \Doctrine\Common\Annotations\AnnotationReader()
269+
)
270+
);
271+
272+
$routes = $loader->load(__DIR__.'/app/controllers/');
273+
274+
$context = new RequestContext('/');
275+
276+
$matcher = new UrlMatcher($routes, $context);
277+
278+
$parameters = $matcher->match($_SERVER['REQUEST_URI']);
279+
258280
The all-in-one Router
259281
~~~~~~~~~~~~~~~~~~~~~
260282

0 commit comments

Comments
 (0)
0