Skip to content

Commit

Permalink
bug #19342 Added class existence check if is_subclass_of() fails in c…
Browse files Browse the repository at this point in the history
…ompiler passes (SCIF)

This PR was merged into the 2.8 branch.

Discussion
----------

Added class existence check if is_subclass_of() fails in compiler passes

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

If you create an event subscriber and make typo in file name it will cause next error:

```
  [InvalidArgumentException]
  Service "event.notification_subscriber" must implement interface "Symfony\Component\EventDispatcher\EventSubscriberInterface".
```

That's because of `is_subclass_of()` fails on class absentee. I made error message more clear.

Commits
-------

72db6e7 Added class existence check if is_subclass_of() fails in compiler passes
  • Loading branch information
fabpot committed Jul 18, 2016
2 parents 88aff45 + 72db6e7 commit 00ab2d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Expand Up @@ -97,9 +97,13 @@ public function process(ContainerBuilder $container)

// We must assume that the class value has been correctly filled, even if the service is created by a factory
$class = $container->getParameterBag()->resolveValue($def->getClass());

$interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';

if (!is_subclass_of($class, $interface)) {
if (!class_exists($class, false)) {
throw new \InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
}

throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
}

Expand Down
Expand Up @@ -54,7 +54,12 @@ public function process(ContainerBuilder $container)

$class = $container->getParameterBag()->resolveValue($def->getClass());
$interface = 'Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface';

if (!is_subclass_of($class, $interface)) {
if (!class_exists($class, false)) {
throw new \InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
}

throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
}

Expand Down

0 comments on commit 00ab2d6

Please sign in to comment.