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

[POC] Metadata and Annotation support #209

Open
wants to merge 3 commits into
base: 3.x
Choose a base branch
from

Conversation

dantleech
Copy link
Member

Q A
Bug fix? no
New feature? yes
BC breaks? no (well, yes, but should be BC when finished)
Deprecations? yes
Tests pass? ?
Fixed tickets
License MIT
Doc PR not yet

This PR adds initial support for Annotations:

use Symfony\Cmf\Bundle\RoutingBundle\Metadata\Annotations as CmfRouting;

/**
 * @PHPCRODM\Document(referenceable=true)
 *
 * @CmfRouting\Template("TestBundle:Content:index.html.twig")
 * @CmfRouting\Controller("cmf_content.controller:indexAction")
 */
class AnnotatedContent

For this I have introduced the jms/metadata package.

To maintain BC we would need to implement a DIC driver for the metadata factory.

Things to do:

  • Add an XML driver (and I guess a YAML driver)
  • Add the DIC driver to maintain BC

)
);
}
if (!empty($config['templates_by_class'])) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to re-add this validation in the metadata layer.

@wouterj
Copy link
Member

wouterj commented Jan 26, 2014

-1 on removing the configuration etc from the extension. Imo, the DIC driver should load the config from the DIC, not the config files. It'll be very hard to create a fully BC DIC driver otherwise.

@dantleech
Copy link
Member Author

@wouterj the DIC driver will indeed load from the DIC -- not sure how yet. I removed the configuration stuff because the validation would now be handled in the metadata layer and before the enhancers were only added when a mapping was present in the DIC config.

* as no controller will be set here.
*/
if (null === $config['generic_controller']) {
throw new InvalidConfigurationException('If you want to configure templates_by_class, you need to configure the generic_controller option.');
Copy link
Member

Choose a reason for hiding this comment

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

need to keep this sanity check too.

@dbu
Copy link
Member

dbu commented Jan 26, 2014

very cool!

i wonder if we should care about the xml and yml (and php) driver or just rely on the container configuration for those. in a separate config file per class, this will be really dispersed all over the place. the annotation makes sense, but for the others i think a central configuration makes more sense. wdyt?

@wouterj
Copy link
Member

wouterj commented Jan 26, 2014

Yeah, I tend to agree with @dbu Maybe having the other formats in here doesn't make much sense.


<!-- Chain Driver !-->
<service
id="cmf_routing.metadata.driver.chain"
Copy link
Member

Choose a reason for hiding this comment

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

I think I prefer using cmf_routing.metadata.driver here

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I think cmf_routing.metadata.driver should be an alias to whatever the driver actually is. So we should still have this definition, e.g. in symfony:

<service id="twig.loader" alias="twig.loader.filesystem" />

@dantleech
Copy link
Member Author

@wouterj @dbu re. the XML, YAML etc, I imagined supporting XML and YAML but its not important I guess - as long as we support the DIC and Annotations then others can be easily added if needed.

@dbu
Copy link
Member

dbu commented Jan 27, 2014

cool. if somebody really wants xml/yml he just can do the PR and if its clean we merge it.

i have somehow the same question as in the other metadata PR: is this not all handled at container compile time? can we not simply upgrade the service configuration with the additional mappings we detect in the compiler pass? or when is the metadata evaluated?

@dantleech
Copy link
Member Author

@dbu the "problem" with evaluating all the mapped classes at compile time is knowing where they are .. you would have to have configuration which points to the mapped classes. When they are loaded on demand we avoid this problem.

Doctrine needs to know where ALL the mapped classes are for creating schemas etc. We simplify things and avoid extra configuration by demanding the metadata from the annotation driver at runtime - I think performance problems would be avoided / largely mitigated by employing a cached annotation driver.

So in short, if collect all the data at compile time we need to infer the location of the mapped objects and do some nasty stuff:

https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php#L167

@dbu
Copy link
Member

dbu commented Jan 29, 2014

Ok, i see the point. What if you instead just add a new MetadataEnhancer and change nothing on the existing impl? Then one could switch the feature off for max performance, and the code would probably be more readable

@dbu
Copy link
Member

dbu commented Feb 1, 2014

what aobut the MetadataEnhancer idea?

@dantleech
Copy link
Member Author

@dbu the bundle's FieldByClassEnhancer is that MetadataEnhancer. I agree that we should provide a flag or something to switch annotation driver on and off, but I think we should always have the metadata aware enhancer.

The AnnotationDriver would be complemented by a ContainerDriver which would load the config from the DI like we do now. We would just add or remove the annotation driver from the chain driver. wdyt?

@dbu
Copy link
Member

dbu commented Feb 2, 2014

what would the MetadataEnhancer do if there is no annotation driver?

what would it mean to have a ContainerDriver, when would it be executed? i would really want to keep it in the DI extension to have early notices of mistakes and to have optimal performance with the configuration compiled right into the cache in prod mode. would it work that way?

@dantleech
Copy link
Member Author

@dbu the MetadataEnhancer would use the chain driver, initially with both ContainerDriver and AnnotationDriver. I think the ContainerDriver would indeed validate at compile time (as could the AnnotationDriver driver if the document locations are explicitly defined - but this is an optimization).

);
}

$configDriver->addMethodCall('registerMapping', array($classFqn, $mapping));
Copy link
Member Author

Choose a reason for hiding this comment

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

The the validation for this mapping will be triggered the first time the configuration driver is instantiated. So it is not as early as you might want, but it the validation is eager and not lazy. See the ConfigurationDriver.

Copy link
Member

Choose a reason for hiding this comment

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

it still means we have to run the validation at runtime rather than compile time, which imho sucks. can't we keep validating here?

Copy link
Member Author

Choose a reason for hiding this comment

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

it would, I think, mean doing the same validation in two places. I guess one way around this problem would be to listen to a cache warming event or similar, that way drivers which are capable of validating their mapped objects (e.g. DI driver, XML, YAML and annotations when possible) can do so eagerly?

@dantleech
Copy link
Member Author

Updated. added a ConfiguationDriver and validation. Although as noted, the validation is done eager and early rather than at compile time.

@dantleech
Copy link
Member Author

I guess this is not going to be in 1.1

@dbu dbu removed this from the 1.2 milestone Apr 25, 2014
@bigfoot90
Copy link

What is the state of this?

@dantleech
Copy link
Member Author

tbh I think we have forgotten about this, maybe it wouldn't be too much work to get it in to the next release //cc @dbu

@dbu
Copy link
Member

dbu commented Nov 19, 2014

yeah, i guess its rather close to being finished. i would want to make it possible to completely disable the feature for performance reasons, but annotations are a nice way for RAD and the xml/yml config can allow a bundle to provide a default configuration how it wants to be handled. with that regard, i think config in the application config should have precedence over annotations or config files by bundles...

@dantleech do you want to rebase this on current master and then we check what is left to do?

@dantleech dantleech self-assigned this Mar 11, 2015
@dbu
Copy link
Member

dbu commented Apr 10, 2015

ping @dantleech

@dantleech
Copy link
Member Author

Would be great, but don't know if I will have time in the near future..

@dbu
Copy link
Member

dbu commented Jun 14, 2016

should we drop this one?

@dantleech
Copy link
Member Author

I think it would be a great feature. But we should try and do it for all bundles in the same way at the same time. But its still not something very high on my list, I don't see any harm in leaving it open as a reference / reminder?

@dbu
Copy link
Member

dbu commented Jun 14, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants