Skip to content

Commit 0748d7c

Browse files
authored
Merge pull request #487 from garak/improve-docs
remove container-related suggestions from docs
2 parents 5f85a49 + 24536da commit 0748d7c

4 files changed

+13
-20
lines changed

docs/disabling_providers.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Disabling the Core Menu Providers
22
=================================
33

44
To be able to use different menu providers together (the builder-service-based
5-
one, the container-based one and the convention-based one for instance),
5+
one, and the convention-based one for instance),
66
a chain provider is used. However, it is not used when only one provider
77
is enabled to increase performance by getting rid of the wrapping. If you
88
don't want to use the built-in providers, you can disable them through the

docs/index.rst

+6-13
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,22 @@ An example builder class would look like this:
130130
use App\Entity\Blog;
131131
use Knp\Menu\FactoryInterface;
132132
use Knp\Menu\ItemInterface;
133-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
134-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
135133
136-
final class Builder implements ContainerAwareInterface
134+
final class Builder
137135
{
138-
use ContainerAwareTrait;
136+
public function __construct(
137+
private EntityManagerInterface $em,
138+
) {
139+
}
139140
140141
public function mainMenu(FactoryInterface $factory, array $options): ItemInterface
141142
{
142143
$menu = $factory->createItem('root');
143144
144145
$menu->addChild('Home', ['route' => 'homepage']);
145146
146-
// access services from the container!
147-
$em = $this->container->get('doctrine')->getManager();
148147
// findMostRecent and Blog are just imaginary examples
149-
$blog = $em->getRepository(Blog::class)->findMostRecent();
148+
$blog = $this->em->getRepository(Blog::class)->findMostRecent();
150149
151150
$menu->addChild('Latest Blog Post', [
152151
'route' => 'blog_show',
@@ -183,12 +182,6 @@ With the standard ``knp_menu.html.twig`` template and your current page being
183182
</li>
184183
</ul>
185184

186-
.. note::
187-
188-
You only need to implement ``ContainerAwareInterface`` if you need the
189-
service container. The more elegant way to handle your dependencies is to
190-
inject them in the constructor. If you want to do that, see the method below.
191-
192185
.. note::
193186

194187
The menu builder can be overwritten using the bundle inheritance.

docs/menu_builder_service.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ Creating Menu Builders as Services
22
==================================
33

44
This bundle gives you a really convenient way to create menus by following
5-
a convention and - if needed - injecting the entire container.
5+
a convention.
66

77
However, if you want to, you can instead choose to create a service for your
88
menu builder. The advantage of this method is that you can inject the exact
9-
dependencies that your menu builder needs, instead of injecting the entire
10-
service container. This can lead to code that is more testable and also potentially
9+
dependencies that your menu builder needs.
10+
This can lead to code that is more testable and also potentially
1111
more reusable. The disadvantage is that it needs just a little more setup.
1212

1313
Start by creating a builder for your menu. You can stick as many menus into

docs/menu_service.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Creating Menus as Services
1313
instead.
1414

1515
This bundle gives you a really convenient way to create menus by following
16-
a convention and - if needed - injecting the entire container.
16+
a convention.
1717

1818
However, if you want to, you can instead choose to create a service for your
1919
menu object. The advantage of this method is that you can inject the exact
20-
dependencies that your menu needs, instead of injecting the entire service
21-
container. This can lead to code that is more testable and also potentially
20+
dependencies that your menu needs.
21+
This can lead to code that is more testable and also potentially
2222
more reusable. The disadvantage is that it needs just a little more setup.
2323

2424
Start by creating a builder for your menu. You can stick as many menus into

0 commit comments

Comments
 (0)