Skip to content
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

Merged
merged 1 commit into from
May 11, 2016

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented Apr 4, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #421
License MIT
Doc PR api-platform/docs#42

TODO:

@soyuka soyuka force-pushed the fileloader branch 3 times, most recently from 0bc3370 to a02e71f Compare April 4, 2016 14:27
@soyuka soyuka changed the title (WIP) File resource configuration (xml,yml) [Wip] File resource configuration (xml,yml) Apr 4, 2016
@soyuka soyuka changed the title [Wip] File resource configuration (xml,yml) [WIP] File resource configuration (xml,yml) Apr 4, 2016
@soyuka soyuka force-pushed the fileloader branch 5 times, most recently from f6012ce to 37f5832 Compare April 5, 2016 10:15
@@ -137,6 +138,35 @@ private function registerAnnotationLoaders(ContainerBuilder $container)
}

/**
* Registers configuration loaders.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configuration file loaders

@soyuka soyuka force-pushed the fileloader branch 3 times, most recently from 021e607 to 7f484e8 Compare April 5, 2016 14:42
$metadata['shortName'] = $reflectionClass->name;
}

$resource = new Resource();
Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We still need the annotation class for annotations.
  2. Why do we need to use this as an intermediate, instead of calling the with... methods of ResourceMetadata directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. ofc
  2. To avoid code repetition in {Annotation,Xml,Yaml}ResourceMetadataFactory? AnnotationResourceMetadataFactory is using an Object to build metadata. Btw I reverted the ApiPlatform\Core\Annotation\Resource file to the original value.

$resourceMetadata = $resourceMetadataFactory->create(ConfigDummy::class);

$this->assertInstanceOf(ResourceMetadata::class, $resourceMetadata);
}
Copy link
Member Author

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
Copy link
Member Author

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

@soyuka soyuka force-pushed the fileloader branch 4 times, most recently from c340705 to c8e4f11 Compare April 5, 2016 15:34
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
use ApiPlatform\Core\Annotation\Resource;

trait ResourceMetadataFactoryTrait
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Member

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

@dunglas
Copy link
Member

dunglas commented Apr 25, 2016

Amazing work @soyuka! Thank you very much.

I left some comment but it's very important improvement to API Platform.

@soyuka
Copy link
Member Author

soyuka commented Apr 29, 2016

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)));
}
Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

@soyuka soyuka force-pushed the fileloader branch 2 times, most recently from 118535a to 2ce7d5e Compare May 11, 2016 06:13
@@ -0,0 +1,73 @@
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
Copy link
Member

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

@soyuka soyuka force-pushed the fileloader branch 3 times, most recently from e24ef7e to 6fada9d Compare May 11, 2016 08:11
@dunglas
Copy link
Member

dunglas commented May 11, 2016

It looks good to me, very helpful work @soyuka, thanks! Do you think this PR is ready to be merged now?

@soyuka
Copy link
Member Author

soyuka commented May 11, 2016

Yes @dunglas It looks good to me!

@dunglas dunglas merged commit 3a6d5c7 into api-platform:master May 11, 2016
@dunglas
Copy link
Member

dunglas commented May 11, 2016

Thank you!

@dunglas
Copy link
Member

dunglas commented May 11, 2016

@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/

@soyuka
Copy link
Member Author

soyuka commented May 11, 2016

@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 The method getAttribute cannot be called on $metadata (of type null). or The variable $xpath does not seem to be defined for all execution paths leading up to this point. (which shows up as "complexity", to me it's more an issue about scrutinizer not checking the loop-declared variables. I want the code to behave like this, but I don't see how it adds any complexity.

I'm willing to do another PR with small fixes no problem ;). Do you already have a release date in mind for the v2?

@teohhanhui
Copy link
Contributor

Thank you @soyuka for seeing this through. I'm going to give this a try in my project...

@teohhanhui
Copy link
Contributor

Uhh, ideally I'd want separate configuration files for each resource. Maybe I'll look into contributing that...

Also, the name resources.{xml,yml} is problematic. We should at least make it api_resources.{xml,yml}

@soyuka soyuka deleted the fileloader branch September 9, 2016 16:01
magarzon pushed a commit to magarzon/core that referenced this pull request Feb 12, 2017
File resource configuration (xml,yml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants