@@ -62,8 +62,7 @@ If you're using the :ref:`default services.yml configuration <service-container-
62
62
This means you can use them immediately without *any * configuration.
63
63
64
64
However, 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:
67
66
68
67
.. configuration-block ::
69
68
@@ -79,8 +78,6 @@ both services. Also, to keep things simple, configure ``TwitterClient`` to be a
79
78
AppBundle\Service\TwitterClient :
80
79
# redundant thanks to _defaults, but value is overridable on each service
81
80
autowire : true
82
- # not required, will help in our example
83
- public : true
84
81
85
82
AppBundle\Util\Rot13Transformer :
86
83
autowire : true
@@ -96,7 +93,7 @@ both services. Also, to keep things simple, configure ``TwitterClient`` to be a
96
93
<defaults autowire =" true" autoconfigure =" true" public =" false" />
97
94
<!-- ... -->
98
95
99
- <service id =" AppBundle\Service\TwitterClient" autowire =" true" public = " true " />
96
+ <service id =" AppBundle\Service\TwitterClient" autowire =" true" />
100
97
101
98
<service id =" AppBundle\Util\Rot13Transformer" autowire =" true" />
102
99
</services >
@@ -111,8 +108,7 @@ both services. Also, to keep things simple, configure ``TwitterClient`` to be a
111
108
112
109
// the autowire method is new in Symfony 3.3
113
110
// in earlier versions, use register() and then call setAutowired(true)
114
- $container->autowire(TwitterClient::class)
115
- ->setPublic(true);
111
+ $container->autowire(TwitterClient::class);
116
112
117
113
$container->autowire(Rot13Transformer::class)
118
114
->setPublic(false);
@@ -130,11 +126,10 @@ Now, you can use the ``TwitterClient`` service immediately in a controller::
130
126
/**
131
127
* @Route("/tweet", methods={"POST"})
132
128
*/
133
- public function tweetAction()
129
+ public function tweetAction(TwitterClient $twitterClient )
134
130
{
135
131
// fetch $user, $key, $status from the POST'ed data
136
132
137
- $twitterClient = $this->container->get(TwitterClient::class);
138
133
$twitterClient->tweet($user, $key, $status);
139
134
140
135
// ...
0 commit comments