Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Updates to DI config for 3.3 #7807

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

Merged
merged 23 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8433fc1
[WIP] Updates to DI config for 3.3
weaverryan Apr 15, 2017
2d11347
more tweaks
weaverryan Apr 28, 2017
105801c
adding note about autoconfigure
weaverryan Apr 28, 2017
049df7d
Adding details and usages of fetching the service as a controller arg
weaverryan Apr 28, 2017
9e84572
last tweaks from feedback
weaverryan Apr 28, 2017
c45daf4
fixing build problem
weaverryan Apr 28, 2017
2636bea
bad link
weaverryan Apr 28, 2017
9ab27f0
Add xml files
GuilhemN Apr 28, 2017
0e48bd8
[WIP] Updates to DI config for 3.3
weaverryan Apr 15, 2017
6e6ed94
more tweaks
weaverryan Apr 28, 2017
70178d1
adding note about autoconfigure
weaverryan Apr 28, 2017
45500b3
Adding details and usages of fetching the service as a controller arg
weaverryan Apr 28, 2017
759e9b2
last tweaks from feedback
weaverryan Apr 28, 2017
6de83e2
fixing build problem
weaverryan Apr 28, 2017
89e12de
bad link
weaverryan Apr 28, 2017
443aec2
Merge pull request #7857 from GuilhemN/patch-1
weaverryan May 2, 2017
bc7088d
Merge remote-tracking branch 'origin/di-3.3-changes' into di-3.3-changes
weaverryan May 2, 2017
ee27765
Adding versionadded
weaverryan May 2, 2017
5452c61
Adding section about public: false
weaverryan May 2, 2017
2229fd3
Merge remote-tracking branch 'origin/master' into di-3.3-changes
weaverryan May 2, 2017
cac3c6c
Merge remote-tracking branch 'origin/master' into di-3.3-changes
weaverryan May 5, 2017
12c4944
Tweaks after amazing review from @GuilhemN and @xabbuh
weaverryan May 5, 2017
22adfbd
removing duplicate target
weaverryan May 5, 2017
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
Prev Previous commit
Next Next commit
Adding versionadded
  • Loading branch information
weaverryan committed May 2, 2017
commit ee2776566da98c0ba360e9ca8f3cde9c835b7cda
7 changes: 7 additions & 0 deletions controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ and many others that you'll learn about next.
via ``$this->get()`` or ``$this->container->get()``. This forces you to write
more robust code to access services, but if you're not use, use ``Controller``.
Copy link
Contributor

@GuilhemN GuilhemN May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would reverse this sentence: but if you're use to fetch dependencies using the container, use Controller, wdyt?


.. versionadded:: 3.3
The ``AbstractController`` class was added in Symfony 3.3.

.. index::
single: Controller; Redirecting

Expand Down Expand Up @@ -237,6 +240,10 @@ The Symfony templating system and Twig are explained more in the
Fetching Services as Arguments
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should addd an anchor for the old headline

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 3.3
The ability to type-hint an argument in order to receive a service was added
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a controller argument?

in Symfony 3.3.

Symfony comes *packed* with a lot of useful objects, called :doc:`services </service_container>`.
These are used for rendering templates, sending emails, querying the database and
any other "work" you can think of.
Expand Down
15 changes: 15 additions & 0 deletions service_container.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ service's class or interface name. Want to :doc:`log </logging>` something? No p
// ...
}

.. versionadded:: 3.3
The ability to type-hint a service in order to receive it was added in Symfony 3.3.

.. _container-debug-container:

What other services are available? Find out by running:
Expand Down Expand Up @@ -177,6 +180,10 @@ the service container *how* to instantiate it:
// app/config/services.php
// _defaults and loading entire directories is not possible with PHP configuration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep a concrete example here for those who really want to use php:

// you have to define your services one-by-one
use AppBundle/Service/MessageGenerator;

$container->autowire(MessageGenerator::class)
    ->setAutoconfigured(true)
    ->setPublic(false);


.. versionadded:: 3.3
The ``_defaults`` key and ability to load services from a directory were added
in Symfony 3.3.

That's it! Thanks to the ``AppBundle\`` line and ``resource`` key below it, a service
will be registered for each class in the ``src/AppBundle/Service`` directory (and
the other directories listed).
Expand Down Expand Up @@ -462,6 +469,11 @@ pass here. No problem! In your configuration, you can explicitly set this argume
->setPublic(false)
->setArgument('$adminEmail', '[email protected]');

.. versionadded:: 3.3
The ability to configure an argument by its name (``$adminEmail``) was added
in Symfony 3.3. Previously, you could configure it only by its index (``2`` in
this case).

Thanks to this, the container will pass ``[email protected]`` as the third argument
to ``__construct`` when creating the ``SiteUpdateManager`` service. The other arguments
will still be autowired.
Expand Down Expand Up @@ -641,6 +653,9 @@ service whose id is ``monolog.logger.request``.
The autoconfigure Option
------------------------

.. versionadded:: 3.3
The ``autoconfigure`` option was added in Symfony 3.3.

Above, we've set ``autoconfigure: true`` in the ``_defaults`` section so that it
applies to all services defined in that file. With this setting, the container will
automatically apply certain configuration to your services, based on your service's
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configurations? or a certain configuration?

Expand Down