@@ -62,8 +62,7 @@ If you're using the :ref:`default services.yaml configuration <service-container
6262This means you can use them immediately without *any * configuration.
6363
6464However, to understand autowiring better, the following examples explicitly configure
65- both services. Also, to keep things simple, configure ``TwitterClient `` to be a
66- :ref: `public <container-public >` service:
65+ both services:
6766
6867.. configuration-block ::
6968
@@ -80,8 +79,6 @@ both services. Also, to keep things simple, configure ``TwitterClient`` to be a
8079 App\Service\TwitterClient :
8180 # redundant thanks to _defaults, but value is overridable on each service
8281 autowire : true
83- # not required, will help in our example
84- public : true
8582
8683 App\Util\Rot13Transformer :
8784 autowire : true
@@ -98,7 +95,7 @@ both services. Also, to keep things simple, configure ``TwitterClient`` to be a
9895 <defaults autowire =" true" autoconfigure =" true" public =" false" />
9996 <!-- ... -->
10097
101- <service id =" App\Service\TwitterClient" autowire =" true" public = " true " />
98+ <service id =" App\Service\TwitterClient" autowire =" true" />
10299
103100 <service id =" App\Util\Rot13Transformer" autowire =" true" />
104101 </services >
@@ -114,8 +111,7 @@ both services. Also, to keep things simple, configure ``TwitterClient`` to be a
114111
115112 // the autowire method is new in Symfony 3.3
116113 // in earlier versions, use register() and then call setAutowired(true)
117- $container->autowire(TwitterClient::class)
118- ->setPublic(true);
114+ $container->autowire(TwitterClient::class);
119115
120116 $container->autowire(Rot13Transformer::class)
121117 ->setPublic(false);
@@ -133,11 +129,10 @@ Now, you can use the ``TwitterClient`` service immediately in a controller::
133129 /**
134130 * @Route("/tweet", methods={"POST"})
135131 */
136- public function tweet()
132+ public function tweet(TwitterClient $twitterClient )
137133 {
138134 // fetch $user, $key, $status from the POST'ed data
139135
140- $twitterClient = $this->container->get(TwitterClient::class);
141136 $twitterClient->tweet($user, $key, $status);
142137
143138 // ...
0 commit comments