File tree Expand file tree Collapse file tree 3 files changed +57
-6
lines changed Expand file tree Collapse file tree 3 files changed +57
-6
lines changed Original file line number Diff line number Diff line change 29
29
"symfony/deprecation-contracts" : " ^2.5|^3" ,
30
30
"symfony/http-foundation" : " ^6.3|^7.0" ,
31
31
"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"
34
33
},
35
34
"require-dev" : {
36
35
"doctrine/collections" : " ^1.6.8|^2.0" ,
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \UX \Autocomplete \Form ;
13
13
14
- use Symfony \Component \String \UnicodeString ;
15
-
16
14
/**
17
15
* All form types that want to expose autocomplete functionality should have this.
18
16
*
@@ -37,13 +35,25 @@ public function getRoute(): string
37
35
return $ this ->route ;
38
36
}
39
37
38
+ /**
39
+ * @internal
40
+ *
41
+ * @param class-string $class
42
+ */
40
43
public static function shortName (string $ class ): string
41
44
{
42
- $ string = new UnicodeString ($ class );
45
+ if ($ pos = (int ) strrpos ($ class , '\\' )) {
46
+ $ class = substr ($ class , $ pos + 1 );
47
+ }
43
48
44
- return $ string -> afterLast ( '\\' )-> snake ()-> toString ( );
49
+ return strtolower ( preg_replace ( ' /([a-z])([A-Z])/ ' , ' $1_$2 ' , $ class ) );
45
50
}
46
51
52
+ /**
53
+ * @internal
54
+ *
55
+ * @param class-string $class
56
+ */
47
57
public static function getInstance (string $ class ): ?self
48
58
{
49
59
$ reflectionClass = new \ReflectionClass ($ class );
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \UX \Autocomplete \Tests \Unit \Form ;
13
+
14
+ use PHPUnit \Framework \TestCase ;
15
+ use Symfony \UX \Autocomplete \Form \AsEntityAutocompleteField ;
16
+ use Symfony \UX \Autocomplete \Tests \Fixtures \Form \ProductType ;
17
+
18
+ class AsEntityAutocompleteFieldTest extends TestCase
19
+ {
20
+ /**
21
+ * @dataProvider provideClassNames
22
+ */
23
+ public function testShortName (string $ shortName , string $ className ): void
24
+ {
25
+ $ this ->assertEquals ($ shortName , AsEntityAutocompleteField::shortName ($ className ));
26
+ }
27
+
28
+ /**
29
+ * @return iterable<{string, string}>
30
+ */
31
+ public static function provideClassNames (): iterable
32
+ {
33
+ yield from [
34
+ ['as_entity_autocomplete_field ' , AsEntityAutocompleteField::class],
35
+ ['product_type ' , ProductType::class],
36
+ ['bar ' , 'Bar ' ],
37
+ ['foo_bar ' , 'FooBar ' ],
38
+ ['foo_bar ' , 'Foo\FooBar ' ],
39
+ ['foo_bar ' , 'Foo\Bar\FooBar ' ],
40
+ ];
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments