Skip to content

Instantly share code, notes, and snippets.

@jfsimon
Created October 11, 2012 13:09
Show Gist options
  • Save jfsimon/3872155 to your computer and use it in GitHub Desktop.
Save jfsimon/3872155 to your computer and use it in GitHub Desktop.
<?php
require_once 'vendor/autoload.php';
$routes = new \Symfony\Component\Routing\RouteCollection();
$routes->add('negotiation', new \Symfony\Component\Routing\Route(
'/negotiation.{_locale}.{_format}',
array(),
array('_locale' => 'fr|en|es', '_format' => 'html|xml'),
array('negotiate' => array('_locale', '_format'))
));
$request = \Symfony\Component\HttpFoundation\Request::create('/negotiation');
$request->headers->set('Accept', 'text/html, text/xml;q=0.9');
$request->headers->set('Accept-Language', 'fr, en;q=0.9');
$context = new \Symfony\Component\Routing\RequestContext();
$context->fromRequest($request);
$router = new \Symfony\Component\Routing\Matcher\UrlMatcher($routes, $context);
$parameters = $router->match('/negotiation');
var_dump($parameters);
// array(4) {
// ["_locale"]=>
// string(2) "fr"
// ["_format"]=>
// string(4) "html"
// ["_charset"]=>
// NULL
// ["_route"]=>
// string(11) "negotiation"
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment