phroute
phroute copied to clipboard
Unicode routing
Hi, How do you enable Unicode in Phroute? I tried changing \w with \pL but it did not work. Any solutions?
- I can't use \x{600}-\x{6FF} becuase phroute considers {} variable only, while they can be use in \x modifier too. Thanks
Any updates?
I finally came up with a tempprorary solution to get Phroute working with Unicode ....
With this function, you can manipulate route data object before saving it to the cache, so when Phroute loads the data from cache it will be unicode ready:
function(RouteCollector $col){
// unicode fix
$obj = $col->getData();
$class = new ReflectionClass(RouteDataArray::class);
$property = $class->getProperty("variableRoutes");
$property->setAccessible(true);
$val = [];
foreach ($property->getValue($obj) as $regex){
$val[] = str_replace("\\w",'\p{L}\p{N}',$regex);
}
$property->setValue($obj,$val);
return $obj;
}
As you see this is not an elegant solution and it may break in newer versions! So it's better to have an official fix for Unicode.
I think you can just use {variable_name}
and it will match unicode too. In order to use the variable you'll need to do urldecode($variable_name)