-
-
Notifications
You must be signed in to change notification settings - Fork 863
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
File resource configuration (xml,yml) #490
Conversation
0bc3370
to
a02e71f
Compare
f6012ce
to
37f5832
Compare
@@ -137,6 +138,35 @@ private function registerAnnotationLoaders(ContainerBuilder $container) | |||
} | |||
|
|||
/** | |||
* Registers configuration loaders. |
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.
configuration file loaders
021e607
to
7f484e8
Compare
$metadata['shortName'] = $reflectionClass->name; | ||
} | ||
|
||
$resource = new Resource(); |
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'm re-using the ApiPlatform\Core\Annotation\Resource
class. Maybe we should consider renaming it?
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.
- We still need the annotation class for annotations.
- Why do we need to use this as an intermediate, instead of calling the
with...
methods ofResourceMetadata
directly?
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.
- ofc
- To avoid code repetition in
{Annotation,Xml,Yaml}ResourceMetadataFactory
?AnnotationResourceMetadataFactory
is using an Object to build metadata. Btw I reverted theApiPlatform\Core\Annotation\Resource
file to the original value.
$resourceMetadata = $resourceMetadataFactory->create(ConfigDummy::class); | ||
|
||
$this->assertInstanceOf(ResourceMetadata::class, $resourceMetadata); | ||
} |
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.
@teohhanhui for example.
Now I need to see if createMetadata
should be kept in the ResourceMetadataFactoryTrait
, which depends on the use of Annotation/Resource
as a pre-metadata class (see 9463498#r58549969).
} | ||
|
||
$operations = []; | ||
//@TODO - Parse annotations/configuration and build OperationResourceMetadataFactory manually |
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.
Here, I'd love to see an Operation merge instead of replacing defaults. Dunno if it's too much or maybe wrong but I'd allow less configuration for adding a custom operation.
@see OperationResourceMetadataFactory
c340705
to
c8e4f11
Compare
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata; | ||
use ApiPlatform\Core\Annotation\Resource; | ||
|
||
trait ResourceMetadataFactoryTrait |
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'm 👎 for this trait due to violation of SRP (single responsibility principle).
In any case, things are most likely to change once you're done rewriting for the current codebase.
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.
This would indeed resolve the issue involving the use of Annotation\Resource
with configuration values.
Still, it's handy for the handleNotFound
method.
foreach ($this->paths as $path) { | ||
$this->xmlParser->loadXML(file_get_contents($path)); | ||
|
||
$xpath = new DOMXpath($this->xmlParser); |
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.
We should create a XML schema to validate the config provided by the user: http://php.net/manual/fr/domdocument.schemavalidate.php
Amazing work @soyuka! Thank you very much. I left some comment but it's very important improvement to API Platform. |
Just so you know, I won't be available until Mar. 8 and I hope I'll have time to update this before the 20th. |
|
||
if (false === @$this->xmlParser->schemaValidate(self::RESOURCE_SCHEMA)) { | ||
throw new \InvalidArgumentException(sprintf('XML Schema loaded from path %s is not valid!', realpath($path))); | ||
} |
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'm not sure about this, not very fond of preventing the Warning.
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.
As far as I can tell, Symfony does it everywhere too:
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.
It looks good to me.
118535a
to
2ce7d5e
Compare
@@ -0,0 +1,73 @@ | |||
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
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.
The XSD isn't related with Symfony (it will be useful if you use the standalone library too).
I suggest src/schema/metadata.xsd
e24ef7e
to
6fada9d
Compare
It looks good to me, very helpful work @soyuka, thanks! Do you think this PR is ready to be merged now? |
Yes @dunglas It looks good to me! |
Thank you! |
@soyuka this PR introduced some Scrutinizr issues (problems are mostly related to the complexity of the XML Loader). Can you take a look? https://scrutinizer-ci.com/g/api-platform/core/inspections/8232a220-c47f-469d-bc1e-81d9716d1e60/code-structure/ |
@dunglas Yes I've worked around some improvements before my last commit. About code repetitions, I could avoid them by using a Trait that shares common methods. But, we discussed this above with @teohhanhui. I could however add a Trait for Xml metadata that shares validation/error printing methods etc. About things like I'm willing to do another PR with small fixes no problem ;). Do you already have a release date in mind for the v2? |
Thank you @soyuka for seeing this through. I'm going to give this a try in my project... |
Uhh, ideally I'd want separate configuration files for each resource. Maybe I'll look into contributing that... Also, the name |
File resource configuration (xml,yml)
TODO: