Skip to content

Commit 187d02e

Browse files
authored
[make:controller][make:crud] Make route names start with 'app_' (#1007)
* [make:controller][make:crud] Make route names start with 'app_' * Use the more appropriate 'asSnakeCase()' method to resolve the service id
1 parent fbeee59 commit 187d02e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/Str.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ public static function asRoutePath(string $value): string
102102

103103
public static function asRouteName(string $value): string
104104
{
105-
return self::asTwigVariable($value);
105+
$routeName = self::asTwigVariable($value);
106+
107+
return str_starts_with($routeName, 'app_') ? $routeName : 'app_'.$routeName;
106108
}
107109

108110
public static function asSnakeCase(string $value): string

src/Test/MakerTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private function getMakerInstance(string $makerClass): MakerInterface
106106
}
107107

108108
// a cheap way to guess the service id
109-
$serviceId = $serviceId ?? sprintf('maker.maker.%s', Str::asRouteName((new \ReflectionClass($makerClass))->getShortName()));
109+
$serviceId = $serviceId ?? sprintf('maker.maker.%s', Str::asSnakeCase((new \ReflectionClass($makerClass))->getShortName()));
110110

111111
return $this->kernel->getContainer()->get($serviceId);
112112
}

tests/StrTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,19 @@ public function asHumanWordsTests()
200200
yield [' FooBar', 'Foo Bar'];
201201
yield [' Foo Bar ', 'Foo Bar'];
202202
}
203+
204+
/**
205+
* @dataProvider provideAsRouteName
206+
*/
207+
public function testAsRouteName(string $value, string $expectedRouteName)
208+
{
209+
$this->assertSame($expectedRouteName, Str::asRouteName($value));
210+
}
211+
212+
public function provideAsRouteName()
213+
{
214+
yield ['Example', 'app_example'];
215+
yield ['AppExample', 'app_example'];
216+
yield ['Apple', 'app_apple'];
217+
}
203218
}

0 commit comments

Comments
 (0)