Skip to content
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

remove container-related suggestions from docs #487

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/disabling_providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Disabling the Core Menu Providers
=================================

To be able to use different menu providers together (the builder-service-based
one, the container-based one and the convention-based one for instance),
one, and the convention-based one for instance),
a chain provider is used. However, it is not used when only one provider
is enabled to increase performance by getting rid of the wrapping. If you
don't want to use the built-in providers, you can disable them through the
Expand Down
19 changes: 6 additions & 13 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,22 @@ An example builder class would look like this:
use App\Entity\Blog;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

final class Builder implements ContainerAwareInterface
final class Builder
{
use ContainerAwareTrait;
public function __construct(
private EntityManagerInterface $em,
) {
}

public function mainMenu(FactoryInterface $factory, array $options): ItemInterface
{
$menu = $factory->createItem('root');

$menu->addChild('Home', ['route' => 'homepage']);

// access services from the container!
$em = $this->container->get('doctrine')->getManager();
// findMostRecent and Blog are just imaginary examples
$blog = $em->getRepository(Blog::class)->findMostRecent();
$blog = $this->em->getRepository(Blog::class)->findMostRecent();

$menu->addChild('Latest Blog Post', [
'route' => 'blog_show',
Expand Down Expand Up @@ -183,12 +182,6 @@ With the standard ``knp_menu.html.twig`` template and your current page being
</li>
</ul>

.. note::

You only need to implement ``ContainerAwareInterface`` if you need the
service container. The more elegant way to handle your dependencies is to
inject them in the constructor. If you want to do that, see the method below.

.. note::

The menu builder can be overwritten using the bundle inheritance.
Expand Down
6 changes: 3 additions & 3 deletions docs/menu_builder_service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Creating Menu Builders as Services
==================================

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

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

Start by creating a builder for your menu. You can stick as many menus into
Expand Down
6 changes: 3 additions & 3 deletions docs/menu_service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Creating Menus as Services
instead.

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

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

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