8000 [Config] Handle Service/EventSubscriberInterface in ReflectionClassResource by nicolas-grekas · Pull Request #25976 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Config] Handle Service/EventSubscriberInterface in ReflectionClassResource #25976

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

Merged
merged 1 commit into from
Feb 4, 2018

Conversation

nicolas-grekas
Copy link
Member
@nicolas-grekas nicolas-grekas commented Jan 30, 2018
Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #25906
License MIT
Doc PR -

@weaverryan that should fix an issue you reported.

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jan 30, 2018
@nicolas-grekas
Copy link
Member Author

Now tested, PR ready.

@nicolas-grekas nicolas-grekas force-pushed the fix-refl-track branch 2 times, most recently from 877e2b1 to 628aab3 Compare January 31, 2018 07:58
@javiereguiluz
Copy link
Member

If this is something that should be documented for end users, please add some description about this feature, some simple code example, etc. Otherwise, please ignore my comment. Thanks!

throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $this->currentId, ServiceSubscriberInterface::class));
}
$this->container->addObjectResource($class);
$class = $r->name;
8000 Copy link
Member

Choose a reason for hiding this comment

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

why is it needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

because the class can be a parameter name that is resolved by getReflectionClass, so we need the resolved name

Copy link
Member

Choose a reason for hiding this comment

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

thanks

@@ -114,7 +117,9 @@ private function computeHash()

private function generateSignature(\ReflectionClass $class)
{
yield $class->getDocComment().$class->getModifiers();
Copy link
Member Author

Choose a reason for hiding this comment

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

$class->getModifiers() can change value at runtime, e.g. on PHP 5.5

@@ -149,6 +154,16 @@ private function generateSignature(\ReflectionClass $class)
yield print_r($defaults, true);
}
}
< 8000 /td>
if ($class->isSubclassOf(EventSubscriberInterface::class)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering whether this interface coming from another component should really be hardcoded here. This means that any other package providing a similar feature has no way to invalidate the container.

Could we make a reusable implementation (using a different resource probably), which would work for such cases ?

Note that I have such use case in my own project, and I will soon have it in KnpMenuBundle too.

Copy link
Member Author

Choose a reason for hiding this comment

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

@stof that's possible, but that's a new feature. Not the target here, but could be done in another PR.

Copy link
Member

Choose a reason for hiding this comment

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

OK, actually, other packages can invalidate the cache, but suffer from the issue of invalidating them too often too.

Can you work on creating such new feature for 4.1 though ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you work on creating such new feature for 4.1 though ?

not quite now, please open an issue :)

Copy link
Member

Choose a reason for hiding this comment

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

done: #25984


if (!$r = $this->container->getReflectionClass($class)) {
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $this->currentId));
} elseif (!$r->isSubclassOf(ServiceSubscriberInterface::class)) {
Copy link
Member

Choose a reason for hiding this comment

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

should just be if, not elseif

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
if (!$r = $container->getReflectionClass($class)) {
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
} elseif (!$r->isSubclassOf(EventSubscriberInterface::class)) {
Copy link
Member

Choose a reason for hiding this comment

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

just if

8000

Copy link
Member
@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

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

Yea, it's a little weird. I like Stof's #25984 idea. This would fix the immediate issue (which does kinda suck... you can see the page loads are almost always 1 second on our KnpU tutorials), and we could change to use #25984 in the future without any BC problems I think.

@nicolas-grekas
Copy link
Member Author

It's not that weird, it's just a type check, that doesn't make it coupling.
#25984 is non trivial because of the deduplication requirement, if we really want to make it correct and performant.

@chalasr
Copy link
Member
chalasr commented Feb 1, 2018

#25984 would happen on 4.1 anyways, isn't it?

@nicolas-grekas nicolas-grekas merged commit 67e821b into symfony:3.4 Feb 4, 2018
nicolas-grekas added a commit that referenced this pull request Feb 4, 2018
…tionClassResource (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[Config] Handle Service/EventSubscriberInterface in ReflectionClassResource

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25906
| License       | MIT
| Doc PR        | -

@weaverryan that should fix an issue you reported.

Commits
-------

67e821b [Config] Handle Service/EventSubscriberInterface in ReflectionClassResource
@nicolas-grekas nicolas-grekas deleted the fix-refl-track branch February 19, 2018 10:35
This was referenced Mar 1, 2018
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.

6 participants
0