-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Reviewed the Bundles cookbook articles #5095
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
Changes from 1 commit
8254761
3dd40b2
c0637b6
8861215
8008ac6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ How to Load Service Configuration inside a Bundle | |
================================================= | ||
|
||
In Symfony, you'll find yourself using many services. These services can be | ||
registered in the `app/config` directory of your application. But when you | ||
registered in the ``app/config/`` directory of your application. But when you | ||
want to decouple the bundle for use in other projects, you want to include the | ||
service configuration in the bundle itself. This article will teach you how to | ||
do that. | ||
|
@@ -15,7 +15,7 @@ Creating an Extension Class | |
--------------------------- | ||
6D4E |
|
|
In order to load service configuration, you have to create a Dependency | ||
Injection Extension for your bundle. This class has some conventions in order | ||
Injection (DI) Extension for your bundle. This class has some conventions in order | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really get why this change is usefull There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A good practice when using acronyms is to introduce them properly before the first time they are used. In this article, we talk about There was a pro 9E7A blem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also just avoid using DI in the docs (which imho were a better practice). But as long as we use them it's imho indeed a good idea to introduce it properly. |
||
to be detected automatically. But you'll later see how you can change it to | ||
your own preferences. By default, the Extension has to comply with the | ||
following conventions: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,16 +15,16 @@ A) Add Composer Dependencies | |
---------------------------- | ||
|
||
Dependencies are managed with Composer, so if Composer is new to you, learn | ||
some basics in `their documentation`_. This has 2 steps: | ||
some basics in `their documentation`_. This involves two steps: | ||
|
||
1) Find out the Name of the Bundle on Packagist | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The README for a bundle (e.g. `FOSUserBundle`_) usually tells you its name | ||
(e.g. ``friendsofsymfony/user-bundle``). If it doesn't, you can search for | ||
the library on the `Packagist.org`_ site. | ||
the bundle on the `Packagist.org`_ site. | ||
|
||
.. note:: | ||
.. tip:: | ||
|
||
Looking for bundles? Try searching at `KnpBundles.com`_: the unofficial | ||
archive of Symfony Bundles. | ||
|
@@ -39,9 +39,12 @@ Now that you know the package name, you can install it via Composer: | |
$ composer require friendsofsymfony/user-bundle | ||
|
||
This will choose the best version for your project, add it to ``composer.json`` | ||
and download the library into the ``vendor/`` directory. If you need a specific | ||
version, add a ``:`` and the version right after the library name (see | ||
`composer require`_). | ||
and download its code into the ``vendor/`` directory. If you need a specific | ||
version, include it as the second argument of the `composer require`_ command: | ||
|
||
.. code-block:: bash | ||
|
||
$ composer require friendsofsymfony/user-bundle "~2.0@dev" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure showing a dev version is great and not confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just an example of using specific version constraints, so I think it doesn't matter to use a dev version. In fact, the example is real because it was copied from the FOSUserBundle documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a real example, but it will promote to install dev versions (not all people understand composer version constraints as good as we do). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking a real-world example is a good idea. But can't we find a better example (without the need to use a dev version)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I've removed the |
||
|
||
B) Enable the Bundle | ||
-------------------- | ||
|
@@ -68,22 +71,46 @@ The only thing you need to do now is register the bundle in ``AppKernel``:: | |
} | ||
} | ||
|
||
By default, Symfony bundles are registered in all the application | ||
:doc:`execution environments <cookbook/configuration/environments>`. If the bundle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing the leading slash here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Thanks. |
||
is meant to be used only in the development or test environments, register it in | ||
the section below:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would replace this sentence by "If the bundle is meant to be used only in some environment, register it within an if statement, like this (where the FOSUserBundle is only available in the dev and test environment)::" |
||
|
||
// app/AppKernel.php | ||
|
||
// ... | ||
class AppKernel extends Kernel | ||
{ | ||
// ... | ||
|
||
public function registerBundles() | ||
{ | ||
$bundles = array( | ||
// ..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we decided to remove the comma |
||
); | ||
|
||
if (in_array($this->getEnvironment(), array('dev', 'test'))) { | ||
$bundles[] = new FOS\UserBundle\FOSUserBundle(); | ||
} | ||
|
||
// ... | ||
} | ||
} | ||
|
||
C) Configure the Bundle | ||
----------------------- | ||
|
||
It's pretty common for a bundle to need some additional setup or configuration | ||
in ``app/config/config.yml``. The bundle's documentation will tell you about | ||
the configuration, but you can also get a reference of the bundle's config | ||
via the ``config:dump-reference`` command. | ||
|
||
For instance, in order to look the reference of the ``assetic`` config you | ||
can use this: | ||
the configuration, but you can also get a reference of the bundle's configuration | ||
via the ``config:dump-reference`` command: | ||
|
||
.. code-block:: bash | ||
|
||
$ app/console config:dump-reference AsseticBundle | ||
|
||
or this: | ||
Instead of the full bundle name, you can also pass the short name used as the root | ||
of the bundle's configuration: | ||
|
||
.. code-block:: bash | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why phpDocumentor if Symfony relies on Sami and other PHPdoc generators are popular too?