How can I make the Segment router sanely process constraints in ZF2?

不想你离开。 提交于 2019-12-11 23:49:53

问题


I'm using the Segment router as a child of one of my main Literal routes in a ZF2 (currently using 2.3.5) application. The router needs to be able to handle Turkish input characters coming in from the URL. My first attempt looked something like this (as a child route):

'book' => array(
    'type' => 'Zend\Mvc\Router\Http\Segment',
    'options' => array(
        'route' => 'kitap/:book[/]',
        'constraints' => array(
            'book' => '[a-zA-ZçÇşŞğĞıİöÖüÜ1-3.+ ]+',
        ),
    ),
),

This mostly worked for everything I needed it to: upper and lower-case letters, numbers up to 3, etc. Then I noticed it wasn't accepting Turkish capital dotted i's (İ) so I started checking. It actually isn't accepting any Turkish characters at all even though the rest of the bits seem to be processed properly.

Even using \w+ does not seem to match (locale not set to Turkish?), but using \S+ does so the router doesn't have a problem with Turkish URLs, it's just the matching that's whacked.

I looked through the source code for the Segment router and it appears to be using preg_match(), which should handle this just fine. What am I missing here?

Edit: This question is about the same problem, but in the Regex router. This even more closely related one deals with the same issue in the Segment router and is nearly a duplicate, but it does not solve my problem as the code demonstrated is against an old version of ZF2 and is neither a drop in match, nor was I able to port it to work against the updated upstream module which appears to handle things a bit differently. I've also filed an upstream bug report hoping this gets fixed there, but I'm still left without a currently working module. I am happy to create a replacement module for my project with this function patched but am not able to figure out the changes to make it work.

来源:https://stackoverflow.com/questions/29097676/how-can-i-make-the-segment-router-sanely-process-constraints-in-zf2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!