@@ -30,30 +30,36 @@ class TypesGenerator
3030 * @see https://github.com/myclabs/php-enum Used enum implementation
3131 */
3232 const ENUM_USE = 'MyCLabs\Enum\Enum ' ;
33+
3334 /**
3435 * @var string
3536 *
3637 * @see https://github.com/doctrine/collections
3738 */
3839 const DOCTRINE_COLLECTION_USE = 'Doctrine\Common\Collections\ArrayCollection ' ;
40+
3941 /**
4042 * @var string
4143 *
4244 * @see https://github.com/myclabs/php-enum Used enum implementation
4345 */
4446 const ENUM_EXTENDS = 'Enum ' ;
47+
4548 /**
4649 * @var string
4750 */
4851 const SCHEMA_ORG_NAMESPACE = 'http://schema.org/ ' ;
52+
4953 /**
5054 * @var string
5155 */
5256 const SCHEMA_ORG_ENUMERATION = 'http://schema.org/Enumeration ' ;
57+
5358 /**
5459 * @var string
5560 */
5661 const SCHEMA_ORG_DOMAIN = 'schema:domainIncludes ' ;
62+
5763 /**
5864 * @var string
5965 */
@@ -147,7 +153,7 @@ public function generate(array $config)
147153 }
148154
149155 if ($ resource ) {
150- $ typesToGenerate [] = $ resource ;
156+ $ typesToGenerate [$ typeName ] = $ resource ;
151157 } else {
152158 $ this ->logger ->warning ('Type "{typeName}" cannot be found. Using "{guessFrom}" type to generate entity. ' , ['typeName ' => $ typeName , 'guessFrom ' => $ typeConfig ['guessFrom ' ]]);
153159 $ type = $ graph ->resource ($ typeConfig ['vocabularyNamespace ' ].$ typeConfig ['guessFrom ' ], 'rdfs:Class ' );
@@ -226,19 +232,25 @@ public function generate(array $config)
226232 }
227233
228234 // 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+ }
235241
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+ }
240245
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 );
242254 }
243255 }
244256
0 commit comments