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

Advanced metadata implementation. #20

Merged
merged 1 commit into from
Dec 17, 2012
Merged

Advanced metadata implementation. #20

merged 1 commit into from
Dec 17, 2012

Conversation

j
Copy link
Contributor

@j j commented Dec 15, 2012

Fixes #19

Before I head to a holiday work party, I wanted to push what I've got so far, only because I have a few questions pertaining to it.

I was crunching it all together just to get it done real fast.

In this attempt, I was going to make it up to the driver to return the class name, but once I got to the FileDriver, and after looking at the old ones, it looks as if metadata files need to be named according to the class it pertains to (with or without the prefix). Which makes me feel that instead of just returning all files that match for the driver, to instead parse suggested class names from the file name / prefix known to the driver.

What do you think @schmittjoh ?

We can then talk about if we should put a warmupCache method or something in the abstract driver to actually cache metadata and such.

None-the-less, this should be a step in a positive direction as far as this library is concerned I'd say.

I'll add the rest of the tests when I know I'm heading in the right direction. I added one showing the finders functionality before i change it.

Happy holidays!

@j
Copy link
Contributor Author

j commented Dec 15, 2012

Tests pass locally, it looks like Travis is failing this due to a missing rakefile. I can review later.

@schmittjoh
Copy link
Owner

Yeah, I think you can put the implemention for getAllClassNames in the AbstractFileDriver and just let it use the file name to infer the class name, no need to delegate to concrete implementations.

I'm also not yet sure about the name Advanced. I'd prefer something less general, just in case that we want to add even more features at some point, but I don't have a good suggestion atm.

@stof
Copy link
Contributor

stof commented Dec 16, 2012

@jstout24 the actual reason of the travis failure is because .travis.yml is missing, and so travis assumes it is a Ruby project.

Btw @schmittjoh, why is travis enabled if there is no config ?

*
* @author Jordan Stout <j@jrdn.org>
*/
class AdvancedDriverChain extends DriverChain implements AdvancedDriverInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need 2 separate DriverChain. This could be directly in the DriverChain (it is fully BC and does not force to add only advanced drivers in it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, yes, I went overboard here. I was quickly trying to get an idea out there before I spent too much time on it so I overlooked the DriverChain itself since I was on a file creating streak ;P

@j
Copy link
Contributor Author

j commented Dec 16, 2012

@schmittjoh I agree on the naming. I feel that all this logic should belong within the classes themselves, but to keep BC, creating extending classes seems to be the only way to go, however, I too don't know what to name it. Will keep it "Advanced" just to move forward.

@stof thanks for reviewing! i'll get on all the changes and try to get a more concrete PR.

@j
Copy link
Contributor Author

j commented Dec 16, 2012

The more I work on it, the more I feel this logic belongs in the classes themselves... Not interested in introducing 1.2.0? :P

@j
Copy link
Contributor Author

j commented Dec 16, 2012

I'll rebase and fix everything later, for now, I'll commit piece by piece to make sense of all the changes.

Anyway, @schmittjoh you're in a way different timezone than I am, so if you want to work on top of this or implement it yourself if you feel that I'm way off, feel free to. I'm hoping to get this functionality soon so I can finish my current project before the holidays and this is the last thing holding me back :(

I ended up keeping some of the interfaces and just having the classes implement them which in turn implement the "basic" interfaces (because in some cases I want to just use the interface.. for example https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/Metadata/Driver/AnnotationDriver.php). Maybe we can keep it this way and eventually bring the two together in a new release if you feel this belongs in the core of the classes.

{
$classes = array();
foreach ($this->drivers as $driver) {
if ($driver instanceof AdvancedDriverInterface) {
Copy link
Owner

Choose a reason for hiding this comment

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

Should we throw an exception if a driver is not implementing the AdvancedDriverInterface? After all, you won't get all class names anymore as soon as there is a driver which does not implement it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm +1 for this, but as @stof mentioned that DriverChain shouldn't force advanced drivers, I did the check instead of an exception.

I see plusses in both situations, but feel that it may cause more problems if we don't add an exception here since the most common use case is to warm-up a cache, or work with all configured metadata (as I am doing).

Let me know what you feel is best and I can include it.

Copy link
Owner

Choose a reason for hiding this comment

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

Alright, let's use an exception then.

@schmittjoh
Copy link
Owner

Apart from my comment above, the code looks good. I'd like to revert the visibility changes, removals of final though unless they are needed.

In terms of BC, it also looks good to me since all interfaces that we introduced are automatically implemented by the respective classes, so there should be no errors afaics.

@j
Copy link
Contributor Author

j commented Dec 17, 2012

Yep, I'll fix all you've requested and put the finals back as I made the abstract and common classes implement advanced (which shouldn't break BC).

All the code in this PR was only tested through the unit tests, but tonight I've been playing with it in the project that I actually needed it's functionality and it works like a charm! 🏄

It's late here and I have work in the AM, but I'll get on these changes tomorrow morning (so your next morning I guess 👅)

@j
Copy link
Contributor Author

j commented Dec 17, 2012

Oh and I'll clean up the commits before you merge this.

@schmittjoh
Copy link
Owner

Looking forward to it :)

@j
Copy link
Contributor Author

j commented Dec 17, 2012

Woot! I see green now! :P

public function getAllClassNames()
{
if (!$this->locator instanceof AdvancedFileLocatorInterface) {
return array();
Copy link
Owner

Choose a reason for hiding this comment

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

I'd say throw an exception here as well to be consistent with the behavior that we have in the other classes.

@schmittjoh
Copy link
Owner

😲 this looks almost perfect, I might even be able to merge this today :)

@j
Copy link
Contributor Author

j commented Dec 17, 2012

Do you want to keep the "Advanced" word for now or think of another name... hmmmm

@j
Copy link
Contributor Author

j commented Dec 17, 2012

@schmittjoh let me know if it's good to go and I can rebase again.

@j
Copy link
Contributor Author

j commented Dec 17, 2012

All I can think of is "Advanced" or "Extra"..... but I still think this should belong in the base classes & interfaces themselves... so perhaps one day we can bump the version and break BC and hope everyone is using 1.1.*

(Since this is a feature anyway)

@schmittjoh
Copy link
Owner

Looks good. Let's go with "Advanced" for now.

@j
Copy link
Contributor Author

j commented Dec 17, 2012

Great!

schmittjoh added a commit that referenced this pull request Dec 17, 2012
Advanced metadata implementation.
@schmittjoh schmittjoh merged commit ddc24ae into schmittjoh:master Dec 17, 2012
@schmittjoh
Copy link
Owner

Thanks for your work!

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.

Ability to eager-load possible metadata
3 participants