8000 minor #18049 [DependencyInjection] Use constructor property promotion… · symfony/symfony-docs@706fb1a · GitHub
[go: up one dir, main page]

Skip to content

Commit 706fb1a

Browse files
committed
minor #18049 [DependencyInjection] Use constructor property promotion (CPP) (OskarStark)
This PR was squashed before being merged into the 6.2 branch. Discussion ---------- [DependencyInjection] Use constructor property promotion (CPP) Commits ------- 3bb31cf [DependencyInjection] Use constructor property promotion (CPP)
2 parents 9fcdd32 + 3bb31cf commit 706fb1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+356
-548
lines changed

cache.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,10 @@ the same key could be invalidated with one function call::
552552

553553
class SomeClass
554554
{
555-
private $myCachePool;
556-
557555
// using autowiring to inject the cache pool
558-
public function __construct(TagAwareCacheInterface $myCachePool)
559-
{
560-
$this->myCachePool = $myCachePool;
556+
public function __construct(
557+
private TagAwareCacheInterface $myCachePool,
558+
) {
561559
}
562560

563561
public function someMethod()

components/console/logger.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ PSR-3 compliant logger::
1919

2020
class MyDependency
2121
{
22-
private $logger;
23-
24-
public function __construct(LoggerInterface $logger)
25-
{
26-
$this->logger = $logger;
22+
public function __construct(
23+
private LoggerInterface $logger,
24+
) {
2725
}
2826

2927
public function doStuff()

components/dependency_injection.rst

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@ so this is passed into the constructor::
5858

5959
class Mailer
6060
{
61-
private $transport;
62-
63-
public function __construct($transport)
64-
{
65-
$this->transport = $transport;
61+
public function __construct(
62+
private $transport,
63+
) {
6664
}
6765

6866
// ...
@@ -99,11 +97,9 @@ like this::
9997

10098
class NewsletterManager
10199
{
102-
private $mailer;
103-
104-
public function __construct(\Mailer $mailer)
105-
{
106-
$this->mailer = $mailer;
100+
public function __construct(
101+
private \Mailer $mailer,
102+
) {
107103
}
108104

109105
// ...

components/event_dispatcher.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,9 @@ order. Start by creating this custom event class and documenting it::
296296
{
297297
public const NAME = 'order.placed';
298298

299-
protected $order;
300-
301-
public function __construct(Order $order)
302-
{
303-
$this->order = $order;
299+
public function __construct(
300+
protected Order $order,
301+
) {
304302
}
305303

306304
public function getOrder(): Order

components/http_foundation.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,9 @@ methods. You can inject this as a service anywhere in your application::
790790

791791
class UserApiNormalizer
792792
{
793-
private UrlHelper $urlHelper;
794-
795-
public function __construct(UrlHelper $urlHelper)
796-
{
797-
$this->urlHelper = $urlHelper;
793+
public function __construct(
794+
private UrlHelper $urlHelper,
795+
) {
798796
}
799797

800798
public function normalize($user)

components/lock.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,10 @@ key of the lock::
8787

8888
class RefreshTaxonomy
8989
{
90-
private object $article;
91-
private Key $key;
92-
93-
public function __construct(object $article, Key $key)
94-
{
95-
$this->article = $article;
96-
$this->key = $key;
90+
public function __construct(
91+
private object $article,
92+
private Key $key,
93+
) {
9794
}
9895

9996
public function getArticle(): object

components/messenger.rst

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,10 @@ you can create your own message sender::
234234

235235
class ImportantActionToEmailSender implements SenderInterface
236236
{
237-
private $mailer;
238-
private $toEmail;
239-
240-
public function __construct(MailerInterface $mailer, string $toEmail)
241-
{
242-
$this->mailer = $mailer;
243-
$this->toEmail = $toEmail;
237+
public function __construct(
238+
private MailerInterface $mailer,
239+
private string $toEmail,
240+
) {
244241
}
245242

246243
public function send(Envelope $envelope): Envelope
@@ -286,13 +283,10 @@ do is to write your own CSV receiver::
286283

287284
class NewOrdersFromCsvFileReceiver implements ReceiverInterface
288285
{
289-
private $serializer;
290-
private $filePath;
291-
292-
public function __construct(SerializerInterface $serializer, string $filePath)
293-
{
294-
$this->serializer = $serializer;
295-
$this->filePath = $filePath;
286+
public function __construct(
287+
private SerializerInterface $serializer,
288+
private string $filePath,
289+
) {
296290
}
297291

298292
public function get(): iterable

components/phpunit_bridge.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -952,11 +952,9 @@ Consider the following example::
952952

953953
class Foo
954954
{
955-
private $bar;
956-
957-
public function __construct(Bar $bar)
958-
{
959-
$this->bar = $bar;
955+
public function __construct(
956+
private Bar $bar,
957+
) {
960958
}
961959

962960
public function fooMethod()

components/property_info.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,12 @@ information from annotations of properties and methods, such as ``@var``,
431431
// src/Domain/Foo.php
432432
class Foo
433433
{
434-
private $bar;
435-
436434
/**
437435
* @param string $bar
438436
*/
439-
public function __construct($bar) {
440-
$this->bar = $bar;
437+
public function __construct(
438+
private $bar,
439+
) {
441440
}
442441
}
443442

components/runtime.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,10 @@ is added in a new class implementing :class:`Symfony\\Component\\Runtime\\Runner
405405

406406
class ReactPHPRunner implements RunnerInterface
407407
{
408-
private $application;
409-
private $port;
410-
411-
public function __construct(RequestHandlerInterface $application, int $port)
412-
{
413-
$this->application = $application;
414-
$this->port = $port;
408+
public function __construct(
409+
private RequestHandlerInterface $application,
410+
private int $port,
411+
) {
415412
}
416413

417414
public function run(): int

0 commit comments

Comments
 (0)
0