File tree Expand file tree Collapse file tree 1 file changed +5
-35
lines changed
Expand file tree Collapse file tree 1 file changed +5
-35
lines changed Original file line number Diff line number Diff line change @@ -261,21 +261,16 @@ this approach allow you to make a service immutable::
261261 {
262262 private $mailer;
263263
264- public function __construct(?MailerInterface $mailer = null)
265- {
266- $this->mailer = $mailer;
267- }
268-
269264 /**
270- *
271- * The @return is required.
272- *
265+ * @required
273266 * @return static
274- *
275267 */
276268 public function withMailer(MailerInterface $mailer)
277269 {
278- return new static($mailer);
270+ $new = clone $this;
271+ $new->mailer = $mailer;
272+
273+ return $new;
279274 }
280275
281276 // ...
@@ -327,31 +322,6 @@ which allow the container to return the newly created service:
327322 $container->register('app.newsletter_manager', NewsletterManager::class)
328323 ->addMethodCall('withMailer', [new Reference('mailer')], true);
329324
330- This example is pretty simple, let's imagine that you have a simple service
331- which use a `LoggerAwareTrait `::
332-
333- class RandomService
334- {
335- use LoggerAwareTrait;
336- }
337-
338- trait LoggerAwareTrait
339- {
340- private $logger;
341-
342- /**
343- * @return static
344- */
345- public function withLogger(LoggerInterface $logger)
346- {
347- $new = clone $this;
348- $new->logger = $logger;
349-
350- return $new;
351- }
352- }
353-
354-
355325 This approach is useful if you need to configure your service according to your needs,
356326so, what are the advantages?
357327
You can’t perform that action at this time.
0 commit comments