Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[Bundles] Better explain how to develop reusable bundles locally#21554
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
81 changes: 78 additions & 3 deletionsbundles.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -143,9 +143,10 @@ to be adjusted if needed: | ||
| .. tip:: | ||
| It's recommended to use the `PSR-4`_ autoload standard on your bundle's | ||
| ``composer.json`` file. Use the namespace as key, and the location of the | ||
| bundle's main class (relative to ``composer.json``) as value. As the main | ||
| class is located in the ``src/`` directory of the bundle: | ||
| .. code-block:: json | ||
| @@ -162,6 +163,80 @@ to be adjusted if needed: | ||
| } | ||
| } | ||
| Developing a Reusable Bundle | ||
| ---------------------------- | ||
| Bundles are meant to be reusable pieces of code that live independently from | ||
| any particular Symfony application. However, a bundle cannot run on its own: it | ||
| must be registered inside an application to execute its code. | ||
| This can be a bit challenging during development. When working on a bundle in | ||
| its own repository, there's no Symfony application around it, so you need a way | ||
| to test your changes inside a real application environment. | ||
| There are two common approaches to do this, depending on whether your bundle has | ||
| already been published or is still under development. | ||
| Using a Local Path Repository | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| If your bundle hasn't been published yet (for example, it's not available on | ||
| Packagist), you can point Composer to your local bundle directory from any | ||
| Symfony application you use for testing. | ||
| Edit the ``composer.json`` file of your application and add this: | ||
| .. code-block:: json | ||
| { | ||
| "repositories": [ | ||
| { | ||
| "type": "path", | ||
| "url": "/path/to/your/AcmeBlogBundle" | ||
javiereguiluz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| ], | ||
| "require": { | ||
| "acme/blog-bundle": "*" | ||
| } | ||
| } | ||
| Then, in your application, install the bundle as usual: | ||
| .. code-block:: terminal | ||
| $ composer require acme/blog-bundle | ||
| Composer will create a symbolic link (symlink) to your local bundle directory, | ||
| so any change you make in the ``AcmeBlogBundle/`` directory is immediately | ||
| visible in the application. You can now enable the bundle in ``config/bundles.php``:: | ||
| return [ | ||
| // ... | ||
| Acme\BlogBundle\AcmeBlogBundle::class => ['all' => true], | ||
| ]; | ||
| This setup is ideal during early development because it allows quick iteration | ||
| without publishing or rebuilding archives. | ||
| Linking an Already Published Bundle | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| If your bundle is already public (for example, it's published on Packagist), | ||
| you can still develop it locally while testing it inside a Symfony application. | ||
| In your application, replace the installed bundle with a symlink to your local | ||
| development copy. For example, if your bundle is installed under | ||
| ``vendor/acme/blog-bundle/`` and your local copy is in ``~/Projects/AcmeBlogBundle/``: | ||
| .. code-block:: terminal | ||
| $ rm -rf vendor/acme/blog-bundle/ | ||
| $ ln -s ~/Projects/AcmeBlogBundle/ vendor/acme/blog-bundle | ||
| Symfony will now use your local bundle directly. You can edit its code, run | ||
| tests, and see the changes immediately. When you're done, restore the vendor | ||
| folder or reinstall the package with Composer to go back to the published version. | ||
| Learn more | ||
| ---------- | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.