14
14
namespace ApiPlatform \SchemaGenerator ;
15
15
16
16
use ApiPlatform \SchemaGenerator \AnnotationGenerator \AnnotationGeneratorInterface ;
17
+ use Doctrine \Common \Collections \ArrayCollection ;
18
+ use Doctrine \Common \Collections \Collection ;
19
+ use MyCLabs \Enum \Enum ;
17
20
use PhpCsFixer \Cache \NullCacheManager ;
18
21
use PhpCsFixer \Differ \NullDiffer ;
19
22
use PhpCsFixer \Error \ErrorsManager ;
@@ -37,27 +40,6 @@ class TypesGenerator
37
40
*/
38
41
public const SCHEMA_ORG_ENUMERATION = 'http://schema.org/Enumeration ' ;
39
42
40
- /**
41
- * @var string
42
- *
43
- * @see https://github.com/myclabs/php-enum Used enum implementation
44
- */
45
- private const ENUM_USE = 'MyCLabs\Enum\Enum ' ;
46
-
47
- /**
48
- * @var string
49
- *
50
- * @see https://github.com/doctrine/collections
51
- */
52
- private const DOCTRINE_COLLECTION_USE = 'Doctrine\Common\Collections\ArrayCollection ' ;
53
-
54
- /**
55
- * @var string
56
- *
57
- * @see https://github.com/myclabs/php-enum Used enum implementation
58
- */
59
- private const ENUM_EXTENDS = 'Enum ' ;
60
-
61
43
/**
62
44
* @var string
63
45
*/
@@ -177,8 +159,8 @@ public function generate(array $config): void
177
159
$ class ['isEnum ' ] = $ this ->isEnum ($ type );
178
160
if ($ class ['isEnum ' ]) {
179
161
$ class ['namespace ' ] = $ typeConfig ['namespace ' ] ?? $ config ['namespaces ' ]['enum ' ];
180
- $ class ['parent ' ] = self :: ENUM_EXTENDS ;
181
- $ class ['uses ' ][] = self :: ENUM_USE ;
162
+ $ class ['parent ' ] = ' Enum ' ;
163
+ $ class ['uses ' ][] = Enum::class ;
182
164
183
165
// Constants
184
166
foreach ($ this ->graphs as $ graph ) {
@@ -263,9 +245,9 @@ public function generate(array $config): void
263
245
264
246
foreach ($ class ['fields ' ] as &$ field ) {
265
247
$ field ['isEnum ' ] = isset ($ classes [$ field ['range ' ]]) && $ classes [$ field ['range ' ]]['isEnum ' ];
266
- $ field ['typeHint ' ] = $ this ->fieldToTypeHint ($ field , $ classes ) ?? false ;
248
+ $ field ['typeHint ' ] = $ this ->fieldToTypeHint ($ config , $ field , $ classes ) ?? false ;
267
249
268
- if (' array ' === $ field ['typeHint ' ]) {
250
+ if ($ field ['isArray ' ]) {
269
251
$ field ['adderRemoverTypeHint ' ] = $ this ->fieldToAdderRemoverTypeHint ($ field , $ classes ) ?? false ;
270
252
}
271
253
}
@@ -513,10 +495,10 @@ private function isDatatype(string $type): bool
513
495
return in_array ($ type , ['Boolean ' , 'DataType ' , 'Date ' , 'DateTime ' , 'Float ' , 'Integer ' , 'Number ' , 'Text ' , 'Time ' , 'URL ' ], true );
514
496
}
515
497
516
- private function fieldToTypeHint (array $ field , array $ classes ): ?string
498
+ private function fieldToTypeHint (array $ config , array $ field , array $ classes ): ?string
517
499
{
518
500
if ($ field ['isArray ' ]) {
519
- return 'array ' ;
501
+ return $ config [ ' doctrine ' ][ ' useCollection ' ] ? ' Collection ' : 'array ' ;
520
502
}
521
503
522
504
return $ this ->fieldToAdderRemoverTypeHint ($ field , $ classes );
@@ -649,11 +631,13 @@ private function generateField(array $config, array $class, \EasyRdf_Resource $t
649
631
'columnPrefix ' => $ columnPrefix ,
650
632
'isId ' => false ,
651
633
];
634
+
652
635
if ($ isArray ) {
653
636
$ class ['hasConstructor ' ] = true ;
654
637
655
- if (isset ($ config ['doctrine ' ]['useCollection ' ]) && $ config ['doctrine ' ]['useCollection ' ] && !in_array (self ::DOCTRINE_COLLECTION_USE , $ class ['uses ' ], true )) {
656
- $ class ['uses ' ][] = self ::DOCTRINE_COLLECTION_USE ;
638
+ if ($ config ['doctrine ' ]['useCollection ' ] && !in_array (ArrayCollection::class, $ class ['uses ' ], true )) {
639
+ $ class ['uses ' ][] = ArrayCollection::class;
640
+ $ class ['uses ' ][] = Collection::class;
657
641
}
658
642
}
659
643
}
0 commit comments