Skip to content

Commit 37e4641

Browse files
committed
[14.x] Use constructor promotion and typed properties in middleware classes
1 parent 42cbdd4 commit 37e4641

File tree

6 files changed

+23
-103
lines changed

6 files changed

+23
-103
lines changed

src/Illuminate/Auth/Middleware/RequirePassword.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,19 @@
99

1010
class RequirePassword
1111
{
12-
/**
13-
* The response factory instance.
14-
*
15-
* @var \Illuminate\Contracts\Routing\ResponseFactory
16-
*/
17-
protected $responseFactory;
18-
19-
/**
20-
* The URL generator instance.
21-
*
22-
* @var \Illuminate\Contracts\Routing\UrlGenerator
23-
*/
24-
protected $urlGenerator;
25-
2612
/**
2713
* The password timeout.
28-
*
29-
* @var int
3014
*/
31-
protected $passwordTimeout;
15+
protected int $passwordTimeout;
3216

3317
/**
3418
* Create a new middleware instance.
35-
*
36-
* @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory
37-
* @param \Illuminate\Contracts\Routing\UrlGenerator $urlGenerator
38-
* @param int|null $passwordTimeout
3919
*/
40-
public function __construct(ResponseFactory $responseFactory, UrlGenerator $urlGenerator, $passwordTimeout = null)
41-
{
42-
$this->responseFactory = $responseFactory;
43-
$this->urlGenerator = $urlGenerator;
20+
public function __construct(
21+
protected ResponseFactory $responseFactory,
22+
protected UrlGenerator $urlGenerator,
23+
?int $passwordTimeout = null,
24+
) {
4425
$this->passwordTimeout = $passwordTimeout ?: 10800;
4526
}
4627

src/Illuminate/Cookie/Middleware/EncryptCookies.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313

1414
class EncryptCookies
1515
{
16-
/**
17-
* The encrypter instance.
18-
*
19-
* @var \Illuminate\Contracts\Encryption\Encrypter
20-
*/
21-
protected $encrypter;
22-
2316
/**
2417
* The names of the cookies that should not be encrypted.
2518
*
@@ -43,12 +36,10 @@ class EncryptCookies
4336

4437
/**
4538
* Create a new CookieGuard instance.
46-
*
47-
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
4839
*/
49-
public function __construct(EncrypterContract $encrypter)
50-
{
51-
$this->encrypter = $encrypter;
40+
public function __construct(
41+
protected EncrypterContract $encrypter,
42+
) {
5243
}
5344

5445
/**

src/Illuminate/Foundation/Http/Middleware/PreventRequestForgery.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ class PreventRequestForgery
2121
use ExcludesPaths,
2222
InteractsWithTime;
2323

24-
/**
25-
* The application instance.
26-
*
27-
* @var \Illuminate\Contracts\Foundation\Application
28-
*/
29-
protected $app;
30-
31-
/**
32-
* The encrypter implementation.
33-
*
34-
* @var \Illuminate\Contracts\Encryption\Encrypter
35-
*/
36-
protected $encrypter;
37-
3824
/**
3925
* The URIs that should be excluded.
4026
*
@@ -72,14 +58,11 @@ class PreventRequestForgery
7258

7359
/**
7460
* Create a new middleware instance.
75-
*
76-
* @param \Illuminate\Contracts\Foundation\Application $app
77-
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
7861
*/
79-
public function __construct(Application $app, Encrypter $encrypter)
80-
{
81-
$this->app = $app;
82-
$this->encrypter = $encrypter;
62+
public function __construct(
63+
protected Application $app,
64+
protected Encrypter $encrypter,
65+
) {
8366
}
8467

8568
/**

src/Illuminate/Http/Middleware/TrustHosts.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77

88
class TrustHosts
99
{
10-
/**
11-
* The application instance.
12-
*
13-
* @var \Illuminate\Contracts\Foundation\Application
14-
*/
15-
protected $app;
16-
1710
/**
1811
* The trusted hosts that have been configured to always be trusted.
1912
*
@@ -30,12 +23,10 @@ class TrustHosts
3023

3124
/**
3225
* Create a new middleware instance.
33-
*
34-
* @param \Illuminate\Contracts\Foundation\Application $app
3526
*/
36-
public function __construct(Application $app)
37-
{
38-
$this->app = $app;
27+
public function __construct(
28+
protected Application $app,
29+
) {
3930
}
4031

4132
/**

src/Illuminate/Session/Middleware/StartSession.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,13 @@
1414

1515
class StartSession
1616
{
17-
/**
18-
* The session manager.
19-
*
20-
* @var \Illuminate\Session\SessionManager
21-
*/
22-
protected $manager;
23-
24-
/**
25-
* The callback that can resolve an instance of the cache factory.
26-
*
27-
* @var callable|null
28-
*/
29-
protected $cacheFactoryResolver;
30-
3117
/**
3218
* Create a new session middleware.
33-
*
34-
* @param \Illuminate\Session\SessionManager $manager
35-
* @param callable|null $cacheFactoryResolver
3619
*/
37-
public function __construct(SessionManager $manager, ?callable $cacheFactoryResolver = null)
38-
{
39-
$this->manager = $manager;
40-
$this->cacheFactoryResolver = $cacheFactoryResolver;
20+
public function __construct(
21+
protected SessionManager $manager,
22+
protected ?callable $cacheFactoryResolver = null,
23+
) {
4124
}
4225

4326
/**

src/Illuminate/View/Middleware/ShareErrorsFromSession.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,12 @@
88

99
class ShareErrorsFromSession
1010
{
11-
/**
12-
* The view factory implementation.
13-
*
14-
* @var \Illuminate\Contracts\View\Factory
15-
*/
16-
protected $view;
17-
1811
/**
1912
* Create a new error binder instance.
20-
*
21-
* @param \Illuminate\Contracts\View\Factory $view
2213
*/
23-
public function __construct(ViewFactory $view)
24-
{
25-
$this->view = $view;
14+
public function __construct(
15+
protected ViewFactory $view,
16+
) {
2617
}
2718

2819
/**

0 commit comments

Comments
 (0)