forked from lexik/LexikJWTAuthenticationBundle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Depreciate injection of Request instances (lexik#200)
| Q | A | ------------- | --- | Branch? | master | BC breaks? | yes (small) | Deprecations? | yes | Tests pass? | yes This depreciates the injection of `Request` instances in order to totally avoid this practice in 2.0. That concerns most of our Event classes. Warning triggered by Scrutinizer: > _Bug_ You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest(). The proposed deprecation way consists into: - adding a default value (null) for constructors/setters arguments type hinted as `Request` (BC break) - document the corresponding properties+members as deprecated - trigger a `E_USER_DEPRECATED` notice when the deprecated methods are called with a Request as argument. The recommended alternative is to inject the RequestStack instead. For `Event` classes, the user will be responsible of injecting the request stack into their event listeners to be able to use it. All changed classes are instantiated internally, I think this should not be an hard BC breaking for most people. Any thoughts? ---------- - [x] Pre-remove the practice from our code (when RequestStack exists) - [x] Documentation needs to be updated with an example of `@request_stack` injection&usage
- Loading branch information
Showing
14 changed files
with
140 additions
and
79 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
/** | ||
* Interface for event classes that are dispatched when a JWT cannot be authenticated. | ||
* | ||
* | ||
* @author Robin Chalas <[email protected]> | ||
*/ | ||
interface JWTFailureEventInterface | ||
|
@@ -19,6 +19,8 @@ interface JWTFailureEventInterface | |
public function getResponse(); | ||
|
||
/** | ||
* @deprecated since 1.7, removed in 2.0 | ||
* | ||
* @return Request | ||
*/ | ||
public function getRequest(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,21 +7,26 @@ | |
use Symfony\Component\Security\Core\Exception\AuthenticationException; | ||
|
||
/** | ||
* JWTNotFoundEvent event is dispatched when a JWT cannot be found in a request | ||
* JWTNotFoundEvent event is dispatched when a JWT cannot be found in a request | ||
* covered by a firewall secured via lexik_jwt. | ||
* | ||
* @author Robin Chalas <[email protected]> | ||
*/ | ||
class JWTNotFoundEvent extends AuthenticationFailureEvent implements JWTFailureEventInterface | ||
{ | ||
/** | ||
* @param Request $request | ||
* @param Request|null $request Deprecated | ||
* @param AuthenticationException|null $exception | ||
* @param Response|null $response | ||
*/ | ||
public function __construct(Request $request, AuthenticationException $exception = null, Response $response = null) | ||
public function __construct(Request $request = null, AuthenticationException $exception = null, Response $response = null) | ||
{ | ||
$this->request = $request; | ||
if (null !== $request && class_exists('Symfony\Component\HttpFoundation\RequestStack')) { | ||
@trigger_error(sprintf('Passing a Request instance as first argument of %s() is deprecated since version 1.7 and will be removed in 2.0.%sInject the "@request_stack" service in your event listener instead.', __METHOD__, PHP_EOL), E_USER_DEPRECATED); | ||
|
||
$this->request = $request; | ||
} | ||
|
||
$this->exception = $exception; | ||
$this->response = $response; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.