[Routing][AnnotationClassLoader] fix utf-8 encoding in default route name
This commit is contained in:
parent
75d1dd45e5
commit
7ab52d3c36
@ -199,7 +199,8 @@ abstract class AnnotationClassLoader implements LoaderInterface
|
|||||||
*/
|
*/
|
||||||
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
|
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
|
||||||
{
|
{
|
||||||
$name = strtolower(str_replace('\\', '_', $class->name).'_'.$method->name);
|
$name = str_replace('\\', '_', $class->name).'_'.$method->name;
|
||||||
|
$name = \function_exists('mb_strtolower') && preg_match('//u', $name) ? mb_strtolower($name, 'UTF-8') : strtolower($name);
|
||||||
if ($this->defaultRouteIndex > 0) {
|
if ($this->defaultRouteIndex > 0) {
|
||||||
$name .= '_'.$this->defaultRouteIndex;
|
$name .= '_'.$this->defaultRouteIndex;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
|
||||||
|
|
||||||
|
class EncodingClass
|
||||||
|
{
|
||||||
|
public function routeÀction()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -324,6 +324,27 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods');
|
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires function mb_strtolower
|
||||||
|
*/
|
||||||
|
public function testDefaultRouteName()
|
||||||
|
{
|
||||||
|
$methodRouteData = [
|
||||||
|
'name' => null,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->reader
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getMethodAnnotations')
|
||||||
|
->will($this->returnValue([$this->getAnnotatedRoute($methodRouteData)]))
|
||||||
|
;
|
||||||
|
|
||||||
|
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\EncodingClass');
|
||||||
|
$defaultName = array_keys($routeCollection->all())[0];
|
||||||
|
|
||||||
|
$this->assertSame($defaultName, 'symfony_component_routing_tests_fixtures_annotatedclasses_encodingclass_routeàction');
|
||||||
|
}
|
||||||
|
|
||||||
private function getAnnotatedRoute($data)
|
private function getAnnotatedRoute($data)
|
||||||
{
|
{
|
||||||
return new Route($data);
|
return new Route($data);
|
||||||
|
@ -29,7 +29,7 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
|
|
||||||
public function testLoad()
|
public function testLoad()
|
||||||
{
|
{
|
||||||
$this->reader->expects($this->exactly(3))->method('getClassAnnotation');
|
$this->reader->expects($this->exactly(4))->method('getClassAnnotation');
|
||||||
|
|
||||||
$this->reader
|
$this->reader
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
@ -52,6 +52,7 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass',
|
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass',
|
||||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\FooClass',
|
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\FooClass',
|
||||||
|
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\EncodingClass',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->reader
|
$this->reader
|
||||||
|
Reference in New Issue
Block a user