Skip to content

Commit

Permalink
Depreciate injection of Request instances
Browse files Browse the repository at this point in the history
Add missing notice-type
  • Loading branch information
chalasr committed Jul 18, 2016
1 parent e84d3ef commit ec56787
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 23 deletions.
18 changes: 15 additions & 3 deletions Event/AuthenticationFailureEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Exception\AuthenticationException;

/**
Expand All @@ -17,6 +18,8 @@ class AuthenticationFailureEvent extends Event
{
/**
* @var Request
*
* @deprecated since 1.7, removed in 2.0
*/
protected $request;

Expand All @@ -31,22 +34,31 @@ class AuthenticationFailureEvent extends Event
protected $response;

/**
* @param Request $request
* @param Request|null $request Deprecated
* @param AuthenticationException $exception
* @param Response $response
*/
public function __construct(Request $request, AuthenticationException $exception, Response $response)
public function __construct(Request $request = null, AuthenticationException $exception, Response $response)
{
$this->request = $request;
if (null !== $request && class_exists(RequestStack::class)) {
@trigger_error(sprintf('Passing a %s instance as first argument of %s() is deprecated since version 1.7 and will be removed in 2.0.\nInject the "@request_stack" service in your event listener instead.', Request::class, __METHOD__, PHP_EOL, RequestStack::class), E_USER_DEPRECATED);

$this->request = $request;
}

$this->exception = $exception;
$this->response = $response;
}

/**
* @deprecated since 1.7, removed in 2.0
*
* @return Request
*/
public function getRequest()
{
@trigger_error(sprintf('Method %s() is deprecated since version 1.7 and will be removed in 2.0.%sInject the "@request_stack" service in your event listener instead, then retrieve the current Request using %s::getCurrentRequest().', __METHOD__, PHP_EOL, RequestStack::class));

return $this->request;
}

Expand Down
17 changes: 15 additions & 2 deletions Event/AuthenticationSuccessEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\User\UserInterface;

/**
Expand All @@ -27,6 +28,8 @@ class AuthenticationSuccessEvent extends Event

/**
* @var Request
*
* @deprecated since 1.7, removed in 2.0
*/
protected $request;

Expand All @@ -38,11 +41,17 @@ class AuthenticationSuccessEvent extends Event
/**
* @param array $data
* @param UserInterface $user
* @param Request $request
* @param Request|null $request Deprecated
* @param Response $response
*/
public function __construct(array $data, UserInterface $user, Request $request, Response $response)
public function __construct(array $data, UserInterface $user, Request $request = null, Response $response)
{
if (null !== $request && class_exists(RequestStack::class)) {
@trigger_error(sprintf('Passing a %s instance as first argument of %s() is deprecated since version 1.7 and will be removed in 2.0.\nInject the "@request_stack" service in your event listener instead.', Request::class, __METHOD__, PHP_EOL, RequestStack::class), E_USER_DEPRECATED);

$this->request = $request;
}

$this->data = $data;
$this->user = $user;
$this->request = $request;
Expand Down Expand Up @@ -74,10 +83,14 @@ public function getUser()
}

/**
* @deprecated since 1.7, removed in 2.0
*
* @return Request
*/
public function getRequest()
{
@trigger_error(sprintf('Method %s() is deprecated since version 1.7 and will be removed in 2.0.%sInject the "@request_stack" service in your event listener instead, then retrieve the current Request using %s::getCurrentRequest().', __METHOD__, PHP_EOL, RequestStack::class));

return $this->request;
}

Expand Down
7 changes: 1 addition & 6 deletions Event/JWTAuthenticatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ class JWTAuthenticatedEvent extends Event
* @var TokenInterface
*/
protected $token;

/**
* @var Request
*/
protected $request;


/**
* @param array $payload
* @param TokenInterface $token
Expand Down
20 changes: 16 additions & 4 deletions Event/JWTCreatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\User\UserInterface;

/**
Expand All @@ -24,19 +25,26 @@ class JWTCreatedEvent extends Event

/**
* @var Request
*
* @deprecated since 1.7, removed in 2.0
*/
protected $request;

/**
* @param array $data
* @param UserInterface $user
* @param Request $request
* @param Request|null $request Deprecated
*/
public function __construct(array $data, UserInterface $user, Request $request = null)
{
$this->data = $data;
$this->user = $user;
$this->request = $request;
if (null !== $request && class_exists(RequestStack::class)) {
@trigger_error(sprintf('Passing a %s instance as first argument of %s() is deprecated since version 1.7 and will be removed in 2.0.\nInject the "@request_stack" service in your event listener instead.', Request::class, __METHOD__, PHP_EOL, RequestStack::class), E_USER_DEPRECATED);

$this->request = $request;
}

$this->data = $data;
$this->user = $user;
}

/**
Expand Down Expand Up @@ -64,10 +72,14 @@ public function getUser()
}

/**
* @deprecated since 1.7, removed in 2.0
*
* @return Request
*/
public function getRequest()
{
@trigger_error(sprintf('Method %s() is deprecated since version 1.7 and will be removed in 2.0.%sInject the "@request_stack" service in your event listener instead, then retrieve the current Request using %s::getCurrentRequest().', __METHOD__, PHP_EOL, RequestStack::class));

return $this->request;
}
}
18 changes: 15 additions & 3 deletions Event/JWTDecodedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* JWTDecodedEvent
Expand All @@ -19,6 +20,8 @@ class JWTDecodedEvent extends Event

/**
* @var Request
*
* @deprecated since 1.7, removed in 2.0
*/
protected $request;

Expand All @@ -28,13 +31,18 @@ class JWTDecodedEvent extends Event
protected $isValid;

/**
* @param array $payload
* @param Request $request
* @param array $payload
* @param Request|null $request Deprecated
*/
public function __construct(array $payload, Request $request = null)
{
if (null !== $request && class_exists(RequestStack::class)) {
@trigger_error(sprintf('Passing a %s instance as first argument of %s() is deprecated since version 1.7 and will be removed in 2.0.\nInject the "@request_stack" service in your event listener instead.', Request::class, __METHOD__, PHP_EOL, RequestStack::class), E_USER_DEPRECATED);

$this->request = $request;
}

$this->payload = $payload;
$this->request = $request;
$this->isValid = true;
}

Expand All @@ -47,10 +55,14 @@ public function getPayload()
}

/**
* @deprecated since 1.7, removed in 2.0
*
* @return Request
*/
public function getRequest()
{
@trigger_error(sprintf('Method %s() is deprecated since version 1.7 and will be removed in 2.0.%sInject the "@request_stack" service in your event listener instead, then retrieve the current Request using %s::getCurrentRequest().', __METHOD__, PHP_EOL, RequestStack::class));

return $this->request;
}

Expand Down
4 changes: 3 additions & 1 deletion Event/JWTFailureEventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* Interface for event classes that are dispatched when a JWT cannot be authenticated.
*
*
* @author Robin Chalas <[email protected]>
*/
interface JWTFailureEventInterface
Expand All @@ -19,6 +19,8 @@ interface JWTFailureEventInterface
public function getResponse();

/**
* @deprecated since 1.7, removed in 2.0
*
* @return Request
*/
public function getRequest();
Expand Down
14 changes: 10 additions & 4 deletions Event/JWTNotFoundEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RequestStack;
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(RequestStack::class)) {
@trigger_error(sprintf('Passing a %s instance as first argument of %s() is deprecated since version 1.7 and will be removed in 2.0.\nInject the "@request_stack" service in your event listener instead.', Request::class, __METHOD__, PHP_EOL, RequestStack::class), E_USER_DEPRECATED);

$this->request = $request;
}

$this->exception = $exception;
$this->response = $response;
}
Expand Down
11 changes: 11 additions & 0 deletions Services/JWTManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ class JWTManager implements JWTManagerInterface

/**
* @var Request
*
* @deprecated since 1.7, removed in 2.0
*/
protected $request;

/**
* @param JWTEncoderInterface $encoder
* @param EventDispatcherInterface $dispatcher
* @param RequestStack $requestStack
* @param int $ttl
*/
public function __construct(JWTEncoderInterface $encoder, EventDispatcherInterface $dispatcher, $ttl)
Expand Down Expand Up @@ -132,10 +135,14 @@ public function setUserIdentityField($userIdentityField)
}

/**
* @deprecated since 1.7, removed in 2.0
*
* @param RequestStack|Request $requestStack
*/
public function setRequest($requestStack)
{
@trigger_error(sprintf('Method %s::%s() is deprecated since version 1.7 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);

if ($requestStack instanceof Request) {
$this->request = $requestStack;
} elseif ($requestStack instanceof RequestStack) {
Expand All @@ -144,10 +151,14 @@ public function setRequest($requestStack)
}

/**
* @deprecated since 1.7, removed in 2.0
*
* @return Request
*/
public function getRequest()
{
@trigger_error(sprintf('Method %s::%s() is deprecated since version 1.7 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);

return $this->request;
}
}

0 comments on commit ec56787

Please sign in to comment.