phroute icon indicating copy to clipboard operation
phroute copied to clipboard

Unicode routing

Open creativefctr opened this issue 8 years ago • 3 comments

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

creativefctr avatar Jun 14 '16 07:06 creativefctr

Any updates?

creativefctr avatar Nov 13 '16 18:11 creativefctr

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.

creativefctr avatar Nov 18 '16 10:11 creativefctr

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)

vsg24 avatar Jun 26 '17 13:06 vsg24