File tree Expand file tree Collapse file tree 3 files changed +48
-6
lines changed Expand file tree Collapse file tree 3 files changed +48
-6
lines changed Original file line number Diff line number Diff line change 2929 "symfony/deprecation-contracts" : " ^2.5|^3" ,
3030 "symfony/http-foundation" : " ^6.3|^7.0" ,
3131 "symfony/http-kernel" : " ^6.3|^7.0" ,
32- "symfony/property-access" : " ^6.3|^7.0" ,
33- "symfony/string" : " ^6.3|^7.0"
32+ "symfony/property-access" : " ^6.3|^7.0"
3433 },
3534 "require-dev" : {
3635 "doctrine/collections" : " ^1.6.8|^2.0" ,
Original file line number Diff line number Diff line change 1111
1212namespace Symfony \UX \Autocomplete \Form ;
1313
14- use Symfony \Component \String \UnicodeString ;
15-
1614/**
1715 * All form types that want to expose autocomplete functionality should have this.
1816 *
@@ -37,13 +35,25 @@ public function getRoute(): string
3735 return $ this ->route ;
3836 }
3937
38+ /**
39+ * @internal
40+ *
41+ * @param class-string $class
42+ */
4043 public static function shortName (string $ class ): string
4144 {
42- $ string = new UnicodeString ($ class );
45+ if ($ pos = (int ) strrpos ($ class , '\\' )) {
46+ $ class = substr ($ class , $ pos + 1 );
47+ }
4348
44- return $ string -> afterLast ( '\\' )-> snake ()-> toString ( );
49+ return strtolower ( preg_replace ( ' /([a-z])([A-Z])/ ' , ' $1_$2 ' , $ class ) );
4550 }
4651
52+ /**
53+ * @internal
54+ *
55+ * @param class-string $class
56+ */
4757 public static function getInstance (string $ class ): ?self
4858 {
4959 $ reflectionClass = new \ReflectionClass ($ class );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Symfony \UX \Autocomplete \Tests \Unit \Form ;
4+
5+ use Symfony \UX \Autocomplete \Form \AsEntityAutocompleteField ;
6+ use PHPUnit \Framework \TestCase ;
7+ use Symfony \UX \Autocomplete \Tests \Fixtures \Form \ProductType ;
8+
9+ class AsEntityAutocompleteFieldTest extends TestCase
10+ {
11+ /**
12+ * @dataProvider provideClassNames
13+ */
14+ public function testShortName (string $ shortName , string $ className ): void
15+ {
16+ $ this ->assertEquals ($ shortName , AsEntityAutocompleteField::shortName ($ className ));
17+ }
18+
19+ /**
20+ * @return iterable<{string, string}>
21+ */
22+ public static function provideClassNames (): iterable
23+ {
24+ yield from [
25+ ['as_entity_autocomplete_field ' , AsEntityAutocompleteField::class],
26+ ['product_type ' , ProductType::class],
27+ ['bar ' , 'Bar ' ],
28+ ['foo_bar ' , 'FooBar ' ],
29+ ['foo_bar ' , 'Foo\FooBar ' ],
30+ ['foo_bar ' , 'Foo\Bar\FooBar ' ],
31+ ];
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments