-
-
Notifications
You must be signed in to change notification settings - Fork 901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support mapping properties in XML and YAML #814
Support mapping properties in XML and YAML #814
Conversation
71a3006
to
c528c92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job!!
$attributes = []; | ||
foreach ($element->attribute as $attribute) { | ||
$value = isset($attribute->attribute[0]) ? $this->getAttributes($attribute) : (string) $attribute; | ||
isset($attribute['name']) ? $attributes[(string) $attribute['name']] = $value : $attributes[] = $value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this hard to read, I'm not found of ternary value attributions, maybe it's just me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this hard to read too. I think an if-else is just fine here.
$parseException->setParsedFile($path); | ||
|
||
throw $parseException; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice one, maybe we should add this to the other Yaml factories!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
c528c92
to
5426fe1
Compare
*/ | ||
private function update(PropertyMetadata $propertyMetadata, array $metadata) : PropertyMetadata | ||
{ | ||
foreach (['description' => 'get', 'readable' => 'is', 'writable' => 'is', 'writableLink' => 'is', 'readableLink' => 'is', 'required' => 'is', 'identifier' => 'is', 'iri' => 'get', 'attributes' => 'get'] as $metadataKey => $accessorPrefix) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably split the array into multiple lines.
|
||
return [ | ||
'description' => (string) $property['description'] ?: null, | ||
'readable' => 'true' === (string) $property['readable'] || 'false' === (string) $property['readable'] ? constant((string) $property['readable']) : null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using XmlUtils::phpize
instead of this trick?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, (string) $property['readable']
can be '0'
or '1'
too according to the XSD spec.
(string) $resource['shortName'] ?? null, | ||
(string) $resource['description'] ?? null, | ||
(string) $resource['iri'] ?? null, | ||
(string) $resource['shortName'] ?: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? What if the shortName
key doesn't exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, anyway I thought this was tested but I've the feeling it is not and should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I am wrong but if an attribute does not exist in a \SimpleXMLElement
class, its value is null
so the result of this expression is never null
(i.e. (string) null
=> ''
).
Example with $resource['foo']
which does not exist:
var_dump($resource); // class SimpleXMLElement
var_dump($resource['foo']); // NULL
var_dump((string) $resource['foo'] ?? null); // string(0) ""
var_dump((string) $resource['foo'] ?: null); // NULL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware of this behavior, nice catch!
65c5cfd
to
865cb42
Compare
Updated with your changes @soyuka @dunglas @teohhanhui. Travis failed due to a depreciation notice from Twig (see twigphp/Twig#2208). This will be fixed by the next release of |
@meyerbaptiste can you use this trick twigphp/Twig#2208 (comment) to make Travis happy please? |
I tested it yesterday, Travis failed again with |
You probably need to bump the minimal Twig version in |
865cb42
to
1fede1a
Compare
It's okay @dunglas, |
return $this->handleNotFound($parentPropertyMetadata, $resourceClass, $property); | ||
} | ||
|
||
if ($parentPropertyMetadata) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null !== $parentPropertyMetadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but #770 (comment).
*/ | ||
private function handleNotFound(PropertyMetadata $parentPropertyMetadata = null, string $resourceClass, string $property) : PropertyMetadata | ||
{ | ||
if ($parentPropertyMetadata) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null !== $parentPropertyMetadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
|
||
$properties = (new \DOMXPath($domDocument))->query(sprintf('//resources/resource[@class="%s"]/property[@name="%s"]', $resourceClass, $propertyName)); | ||
|
||
if (false === $properties || 0 >= $properties->length || null === $properties->item(0) || false === $property = simplexml_import_dom($properties->item(0))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change this for the sake of lisibility ?
if ( blabla
||
blabla)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done @Simperfit.
37c48e1
to
1a6afd1
Compare
1a6afd1
to
ef5d037
Compare
Thanks @meyerbaptiste. Don't forget to update the docs please. |
…operty_configuration Support mapping properties in XML and YAML
This PR adds support of mapping for properties in XML and YAML.
I followed the recommendations from #421.