@@ -30,30 +30,36 @@ class TypesGenerator
30
30
* @see https://github.com/myclabs/php-enum Used enum implementation
31
31
*/
32
32
const ENUM_USE = 'MyCLabs\Enum\Enum ' ;
33
+
33
34
/**
34
35
* @var string
35
36
*
36
37
* @see https://github.com/doctrine/collections
37
38
*/
38
39
const DOCTRINE_COLLECTION_USE = 'Doctrine\Common\Collections\ArrayCollection ' ;
40
+
39
41
/**
40
42
* @var string
41
43
*
42
44
* @see https://github.com/myclabs/php-enum Used enum implementation
43
45
*/
44
46
const ENUM_EXTENDS = 'Enum ' ;
47
+
45
48
/**
46
49
* @var string
47
50
*/
48
51
const SCHEMA_ORG_NAMESPACE = 'http://schema.org/ ' ;
52
+
49
53
/**
50
54
* @var string
51
55
*/
52
56
const SCHEMA_ORG_ENUMERATION = 'http://schema.org/Enumeration ' ;
57
+
53
58
/**
54
59
* @var string
55
60
*/
56
61
const SCHEMA_ORG_DOMAIN = 'schema:domainIncludes ' ;
62
+
57
63
/**
58
64
* @var string
59
65
*/
@@ -147,7 +153,7 @@ public function generate(array $config)
147
153
}
148
154
149
155
if ($ resource ) {
150
- $ typesToGenerate [] = $ resource ;
156
+ $ typesToGenerate [$ typeName ] = $ resource ;
151
157
} else {
152
158
$ this ->logger ->warning ('Type "{typeName}" cannot be found. Using "{guessFrom}" type to generate entity. ' , ['typeName ' => $ typeName , 'guessFrom ' => $ typeConfig ['guessFrom ' ]]);
153
159
$ type = $ graph ->resource ($ typeConfig ['vocabularyNamespace ' ].$ typeConfig ['guessFrom ' ], 'rdfs:Class ' );
@@ -226,19 +232,25 @@ public function generate(array $config)
226
232
}
227
233
228
234
// Fields
229
- foreach ( $ propertiesMap [ $ type -> getUri ()] as $ property ) {
230
- // Ignore properties not set if using a config file
231
- if ( $ typeConfig [ ' allProperties ' ] || ( is_array ( $ typeConfig [ ' properties ' ]) && array_key_exists ( $ property -> localName (), $ typeConfig [ ' properties ' ])) ) {
232
- $ class = $ this -> generateField ( $ config , $ class , $ type , $ typeName , $ property ->localName (), $ property );
233
- }
234
- }
235
+ if (! $ typeConfig [ ' allProperties ' ] && isset ( $ typeConfig [ ' properties ' ]) && is_array ( $ typeConfig [ ' properties ' ]) ) {
236
+ foreach ( $ typeConfig [ ' properties ' ] as $ key => $ value ) {
237
+ foreach ( $ propertiesMap [ $ type -> getUri ()] as $ property ) {
238
+ if ( $ key !== $ property ->localName ()) {
239
+ continue ;
240
+ }
235
241
236
- // Add custom fields (non schema.org)
237
- if (isset ($ typeConfig ['properties ' ]) && is_array ($ typeConfig ['properties ' ])) {
238
- foreach (array_diff_key ($ typeConfig ['properties ' ], $ class ['fields ' ]) as $ propertyName => $ property ) {
239
- $ this ->logger ->info (sprintf ('The property "%s" (type "%s") is a custom property. ' , $ propertyName , $ type ->localName ()));
242
+ $ class = $ this ->generateField ($ config , $ class , $ type , $ typeName , $ property ->localName (), $ property );
243
+ continue 2 ;
244
+ }
240
245
241
- $ class = $ this ->generateField ($ config , $ class , $ type , $ typeName , $ propertyName );
246
+ // Add custom fields (non schema.org)
247
+ $ this ->logger ->info (sprintf ('The property "%s" (type "%s") is a custom property. ' , $ key , $ type ->localName ()));
248
+ $ class = $ this ->generateField ($ config , $ class , $ type , $ typeName , $ key );
249
+ }
250
+ } else {
251
+ // All properties
252
+ foreach ($ propertiesMap [$ type ->getUri ()] as $ property ) {
253
+ $ class = $ this ->generateField ($ config , $ class , $ type , $ typeName , $ property ->localName (), $ property );
242
254
}
243
255
}
244
256
0 commit comments