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

Throwing an exception if the class is not found #22531

Closed

Conversation

weaverryan
Copy link
Member

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

We now throw an exception if the user makes a mistake with their PSR-4 prefix and namespace. For example:

AppBundle\Controller\:
    resource: '../../src/AppBundle/{Controller}'
    public: true

I should not have the \Controller at the end of the key. Previously, it would silently not import any services from the directory. Now it throws:

Expected to find class "AppBundle\Controller\Controller\Admin\BlogController" in file "/path/to/project/src/AppBundle/Controller/Admin/BlogController.php" while importing services from resource "../../src/AppBundle/{Controller}", but it was not found! Check the namespace prefix used with the resource.

The only "downside" is that this prevents someone from importing files from a resource that has a file with no class in it (functions.php). @nicolas-grekas and I decided today that we can throw an exception now to be safe, and see if anyone has that valid use-case.

Cheers!

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍

@nicolas-grekas
Copy link
Member

oups, tests are failing

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Apr 26, 2017
@weaverryan weaverryan force-pushed the exception-bad-psr4-loader-class branch from a55db04 to 07a162c Compare April 26, 2017 21:22
@weaverryan
Copy link
Member Author

Tests should be happy now. There is one other behavior change that caused the failure: if a class that we try to load extends a non-existent class, then:

  • Before, we silently skipped loading that service
  • After, we allow the normal, fatal, class not found error

I think this is perfectly in spirit with this change, which is: fail if something is wrong :). If someone comes up with a use-case later to NOT fail, we can update the behavior without any BC issues.

@nicolas-grekas
Copy link
Member

Thank you @weaverryan.

@weaverryan weaverryan deleted the exception-bad-psr4-loader-class branch April 27, 2017 15:05
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.

None yet

3 participants