-
Notifications
You must be signed in to change notification settings - Fork 78
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
base: 3.x
Are you sure you want to change the base?
Conversation
) | ||
); | ||
} | ||
if (!empty($config['templates_by_class'])) { |
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.
Need to re-add this validation in the metadata layer.
-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. |
@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.'); |
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.
need to keep this sanity check too.
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? |
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" |
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 think I prefer using cmf_routing.metadata.driver
here
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.
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" />
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? |
@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: |
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 |
what aobut the MetadataEnhancer idea? |
@dbu the bundle's 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? |
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? |
@dbu the MetadataEnhancer would use the chain driver, initially with both |
); | ||
} | ||
|
||
$configDriver->addMethodCall('registerMapping', array($classFqn, $mapping)); |
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 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.
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 still means we have to run the validation at runtime rather than compile time, which imho sucks. can't we keep validating here?
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 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?
Updated. added a |
I guess this is not going to be in 1.1 |
What is the state of this? |
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 |
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? |
ping @dantleech |
Would be great, but don't know if I will have time in the near future.. |
should we drop this one? |
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? |
okay, no harm in keeping it open if its still relevant.
|
This PR adds initial support for Annotations:
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: