Skip to content

Update best_practices.rst #10559

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

Closed
wants to merge 1 commit into from
Closed

Conversation

ThomasLandauer
Copy link
Contributor

Example of autoload in composer.json

Example of `autoload` in `composer.json`
@ThomasLandauer
Copy link
Contributor Author

Some questions:

  • Is this really necessary? None of the bundles in my vendor dir has it:

By convention, the getName() method of the bundle class should return the class name.

  • It also works without an alias. For configuration in services.yaml, it's recommended (with autowiring) to use just the service namespace as id. So is this still relevant at all? Or just in some (which?) cases?

Each bundle has an alias, which is the lower-cased short version of the bundle name using underscores (acme_blog for AcmeBlogBundle). This alias is used to enforce uniqueness within a project and for defining bundle's configuration options (see below for some usage examples).

@@ -521,7 +521,9 @@ The ``composer.json`` file should include at least the following metadata:

``autoload``
This information is used by Symfony to load the classes of the bundle. It's
recommended to use the `PSR-4`_ autoload standard.
recommended to use the `PSR-4`_ autoload standard. Use the namespace as key,
Copy link
Member

Choose a reason for hiding this comment

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

It'd suggest a colon instead of a dot: standard: use

recommended to use the `PSR-4`_ autoload standard.
recommended to use the `PSR-4`_ autoload standard. Use the namespace as key,
and the location of the bundle's main class (relative to ``composer.json``)
as value, example: ``"autoload": { "psr-4": { "JohnSmith\\BlogBundle\\": "" } }``
Copy link
Member

Choose a reason for hiding this comment

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

adding src/ in the example would be even more descriptive (and is common practice):
"autoload": { "psr-4": { "JohnSmith\\BlogBundle\\": "src/" } }

@javiereguiluz
Copy link
Member

Thank you for this contribution Thomas. We merged it in 4.2 branch (that's why GitHub displays as "closed" instead of "merged", but it's merged). We also applied Nico's suggestions while merging.

@javiereguiluz javiereguiluz added this to the 4.2 milestone May 3, 2019
@ThomasLandauer ThomasLandauer deleted the patch-3 branch May 4, 2019 12:52
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.

4 participants