Skip to content

Commit 68b8183

Browse files
committed
[HttpKernel] Added support for registering Bundle dependencies
Doc for : symfony/symfony#13945
1 parent adf5b90 commit 68b8183

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

cookbook/bundles/dependencies.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.. index::
2+
single: Bundle; Dependencies
3+
4+
How to Use Bundle Dependencies to Load other Bundles
5+
====================================================
6+
7+
.. versionadded:: 2.7
8+
Support for bundle dependencies was introduced in Symfony 2.7.
9+
10+
When working on your own bundle(s), you'll sometimes have the need to reuse
11+
other bundles, either by just requiring, overriding or inheriting from them.
12+
13+
While Composer takes care about making sure these dependencies are loaded,
14+
you'll also need to enable these bundles in the kernel.
15+
16+
If your bundle is meant to be reused, bundle dependencies will complicate
17+
your installation documentation. This makes installation and upgrading your
18+
bundle more tedious for your users.
19+
20+
You can avoid this by specifying your dependencies. This will make sure that
21+
they are loaded in the kernel. It'll also make sure they are loaded *before*
22+
your own bundle, to make sure you can extend them.
23+
24+
Specifying dependencies is accomplished by implementing the
25+
:class:`Symfony\\Component\\HttpKernel\\Bundle\\BundleDependenciesInterface`::
26+
27+
// src/CacheBundle/CacheBundle.php
28+
namespace CacheBundle;
29+
30+
use Symfony\Component\HttpKernel\Bundle\Bundle;
31+
use Symfony\Component\HttpKernel\Bundle\BundleDependenciesInterface;
32+
33+
class CacheBundle extends Bundle implements BundleDependenciesInterface
34+
{
35+
public function getBundleDependencies()
36+
{
37+
return array('FOS\HttpCacheBundle\FOSHttpCacheBundle');
38+
}
39+
}
40+
41+
.. tip::
42+
43+
If your bundle requires PHP 5.5 or higher, you can also take advantage of
44+
the ``CLASS`` constant::
45+
46+
use FOS\HttpCacheBundle\FOSHttpCacheBundle;
47+
48+
// ...
49+
public function getBundleDependencies()
50+
{
51+
return array(FOSHttpCacheBundle::CLASS);
52+
}

cookbook/bundles/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Bundles
77
installation
88
best_practices
99
inheritance
10+
dependencies
1011
override
1112
remove
1213
extension

cookbook/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* :doc:`/cookbook/bundles/installation`
1212
* :doc:`/cookbook/bundles/best_practices`
1313
* :doc:`/cookbook/bundles/inheritance`
14+
* :doc:`/cookbook/bundles/dependencies`
1415
* :doc:`/cookbook/bundles/override`
1516
* :doc:`/cookbook/bundles/remove`
1617
* :doc:`/cookbook/bundles/extension`

0 commit comments

Comments
 (0)