Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18240e2

Browse files
[Form] Drop remaing CsrfProviderAdapter/Interface mentions
1 parent 8988409 commit 18240e2

9 files changed

+11
-101
lines changed

src/Symfony/Component/Form/Extension/Csrf/CsrfExtension.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\Form\Extension\Csrf;
1313

1414
use Symfony\Component\Form\Exception\UnexpectedTypeException;
15-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
16-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1715
use Symfony\Component\Form\AbstractExtension;
1816
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
1917
use Symfony\Component\Translation\TranslatorInterface;
@@ -47,14 +45,8 @@ class CsrfExtension extends AbstractExtension
4745
* @param TranslatorInterface $translator The translator for translating error messages
4846
* @param null|string $translationDomain The translation domain for translating
4947
*/
50-
public function __construct($tokenManager, TranslatorInterface $translator = null, $translationDomain = null)
48+
public function __construct(CsrfTokenManagerInterface $tokenManager, TranslatorInterface $translator = null, $translationDomain = null)
5149
{
52-
if ($tokenManager instanceof CsrfProviderInterface) {
53-
$tokenManager = new CsrfProviderAdapter($tokenManager);
54-
} elseif (!$tokenManager instanceof CsrfTokenManagerInterface) {
55-
throw new UnexpectedTypeException($tokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
56-
}
57-
5850
$this->tokenManager = $tokenManager;
5951
$this->translator = $translator;
6052
$this->translationDomain = $translationDomain;

src/Symfony/Component/Form/Extension/Csrf/EventListener/CsrfValidationListener.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1515
use Symfony\Component\Form\Exception\UnexpectedTypeException;
16-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
17-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1816
use Symfony\Component\Form\FormEvents;
1917
use Symfony\Component\Form\FormError;
2018
use Symfony\Component\Form\FormEvent;
@@ -75,14 +73,8 @@ public static function getSubscribedEvents()
7573
);
7674
}
7775

78-
public function __construct($fieldName, $tokenManager, $tokenId, $errorMessage, TranslatorInterface $translator = null, $translationDomain = null)
76+
public function __construct($fieldName, CsrfTokenManagerInterface $tokenManager, $tokenId, $errorMessage, TranslatorInterface $translator = null, $translationDomain = null)
7977
{
80-
if ($tokenManager instanceof CsrfProviderInterface) {
81-
$tokenManager = new CsrfProviderAdapter($tokenManager);
82-
} elseif (!$tokenManager instanceof CsrfTokenManagerInterface) {
83-
throw new UnexpectedTypeException($tokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
84-
}
85-
8678
$this->fieldName = $fieldName;
8779
$this->tokenManager = $tokenManager;
8880
$this->tokenId = $tokenId;

src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php

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

1414
use Symfony\Component\Form\AbstractTypeExtension;
1515
use Symfony\Component\Form\Exception\UnexpectedTypeException;
16-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
17-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1816
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfTokenManagerAdapter;
1917
use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener;
2018
use Symfony\Component\Form\FormBuilderInterface;
@@ -55,14 +53,8 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
5553
*/
5654
private $translationDomain;
5755

58-
public function __construct($defaultTokenManager, $defaultEnabled = true, $defaultFieldName = '_token', TranslatorInterface $translator = null, $translationDomain = null)
56+
public function __construct(CsrfTokenManagerInterface $defaultTokenManager, $defaultEnabled = true, $defaultFieldName = '_token', TranslatorInterface $translator = null, $translationDomain = null)
5957
{
60-
if ($defaultTokenManager instanceof CsrfProviderInterface) {
61-
$defaultTokenManager = new CsrfProviderAdapter($defaultTokenManager);
62-
} elseif (!$defaultTokenManager instanceof CsrfTokenManagerInterface) {
63-
throw new UnexpectedTypeException($defaultTokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
64-
}
65-
6658
$this->defaultTokenManager = $defaultTokenManager;
6759
$this->defaultEnabled = $defaultEnabled;
6860
$this->defaultFieldName = $defaultFieldName;
@@ -121,30 +113,12 @@ public function finishView(FormView $view, FormInterface $form, array $options)
121113
*/
122114
public function configureOptions(OptionsResolver $resolver)
123115
{
124-
// BC clause for the "intention" option
125-
$csrfTokenId = function (Options $options) {
126-
return $options['intention'];
127-
};
128-
129-
// BC clause for the "csrf_provider" option
130-
$csrfTokenManager = function (Options $options) {
131-
if ($options['csrf_provider'] instanceof CsrfTokenManagerInterface) {
132-
return $options['csrf_provider'];
133-
}
134-
135-
return $options['csrf_provider'] instanceof CsrfTokenManagerAdapter
136-
? $options['csrf_provider']->getTokenManager(false)
137-
: new CsrfProviderAdapter($options['csrf_provider']);
138-
};
139-
140116
$resolver->setDefaults(array(
141117
'csrf_protection' => $this->defaultEnabled,
142118
'csrf_field_name' => $this->defaultFieldName,
143119
'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.',
144-
'csrf_token_manager' => $csrfTokenManager,
145-
'csrf_token_id' => $csrfTokenId,
146-
'csrf_provider' => $this->defaultTokenManager,
147-
'intention' => null,
120+
'csrf_token_manager' => $this->defaultTokenManager,
121+
'csrf_token_id' => null,
148122
));
149123
}
150124

src/Symfony/Component/Form/Extension/Templating/TemplatingExtension.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
use Symfony\Component\Form\AbstractExtension;
1515
use Symfony\Component\Form\Exception\UnexpectedTypeException;
16-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
17-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1816
use Symfony\Component\Form\FormRenderer;
1917
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
2018
use Symfony\Component\Templating\PhpEngine;
@@ -27,14 +25,8 @@
2725
*/
2826
class TemplatingExtension extends AbstractExtension
2927
{
30-
public function __construct(PhpEngine $engine, $csrfTokenManager = null, array $defaultThemes = array())
28+
public function __construct(PhpEngine $engine, CsrfTokenManagerInterface $csrfTokenManager = null, array $defaultThemes = array())
3129
{
32-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
33-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
34-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
35-
throw new UnexpectedTypeException($csrfTokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
36-
}
37-
3830
$engine->addHelpers(array(
3931
new FormHelper(new FormRenderer(new TemplatingRendererEngine($engine, $defaultThemes), $csrfTokenManager)),
4032
));

src/Symfony/Component/Form/FormRenderer.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
use Symfony\Component\Form\Exception\LogicException;
1515
use Symfony\Component\Form\Exception\BadMethodCallException;
1616
use Symfony\Component\Form\Exception\UnexpectedTypeException;
17-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
18-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1917
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
2018

2119
/**
@@ -60,14 +58,8 @@ class FormRenderer implements FormRendererInterface
6058
*
6159
* @throws UnexpectedTypeException
6260
*/
63-
public function __construct(FormRendererEngineInterface $engine, $csrfTokenManager = null)
61+
public function __construct(FormRendererEngineInterface $engine, CsrfTokenManagerInterface $csrfTokenManager = null)
6462
{
65-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
66-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
67-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
68-
throw new UnexpectedTypeException($csrfTokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface or null');
69-
}
70-
7163
$this->engine = $engine;
7264
$this->csrfTokenManager = $csrfTokenManager;
7365
}

src/Symfony/Component/Security/Http/Firewall/LogoutListener.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Security\Http\Firewall;
1313

14-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
15-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1614
use Symfony\Component\HttpFoundation\Request;
1715
use Symfony\Component\HttpFoundation\Response;
1816
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
@@ -49,14 +47,8 @@ class LogoutListener implements ListenerInterface
4947
* @param array $options An array of options to process a logout attempt
5048
* @param CsrfTokenManagerInterface $csrfTokenManager A CsrfTokenManagerInterface instance
5149
*/
52-
public function __construct(TokenStorageInterface $tokenStorage, HttpUtils $httpUtils, LogoutSuccessHandlerInterface $successHandler, array $options = array(), $csrfTokenManager = null)
50+
public function __construct(TokenStorageInterface $tokenStorage, HttpUtils $httpUtils, LogoutSuccessHandlerInterface $successHandler, array $options = array(), CsrfTokenManagerInterface $csrfTokenManager = null)
5351
{
54-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
55-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
56-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
57-
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
58-
}
59-
6052
$this->tokenStorage = $tokenStorage;
6153
$this->httpUtils = $httpUtils;
6254
$this->options = array_merge(array(

src/Symfony/Component/Security/Http/Firewall/SimpleFormAuthenticationListener.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\Security\Http\Firewall;
1313

1414
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
15-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
16-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1715
use Symfony\Component\HttpFoundation\Request;
1816
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
1917
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
@@ -58,18 +56,12 @@ class SimpleFormAuthenticationListener extends AbstractAuthenticationListener
5856
* @throws \InvalidArgumentException In case no simple authenticator is provided
5957
* @throws InvalidArgumentException In case an invalid CSRF token manager is passed
6058
*/
61-
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $csrfTokenManager = null, SimpleFormAuthenticatorInterface $simpleAuthenticator = null)
59+
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, CsrfTokenManagerInterface $csrfTokenManager = null, SimpleFormAuthenticatorInterface $simpleAuthenticator = null)
6260
{
6361
if (!$simpleAuthenticator) {
6462
throw new \InvalidArgumentException('Missing simple authenticator');
6563
}
6664

67-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
68-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
69-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
70-
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
71-
}
72-
7365
$this->simpleAuthenticator = $simpleAuthenticator;
7466
$this->csrfTokenManager = $csrfTokenManager;
7567

src/Symfony/Component/Security/Http/Firewall/UsernamePasswordFormAuthenticationListener.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Security\Http\Firewall;
1313

14-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
15-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1614
use Symfony\Component\HttpFoundation\Request;
1715
use Psr\Log\LoggerInterface;
1816
use Symfony\Component\Security\Csrf\CsrfToken;
@@ -40,14 +38,8 @@ class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationL
4038
{
4139
private $csrfTokenManager;
4240

43-
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $csrfTokenManager = null)
41+
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, CsrfTokenManagerInterface $csrfTokenManager = null)
4442
{
45-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
46-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
47-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
48-
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
49-
}
50-
5143
parent::__construct($tokenStorage, $authenticationManager, $sessionStrategy, $httpUtils, $providerKey, $successHandler, $failureHandler, array_merge(array(
5244
'username_parameter' => '_username',
5345
'password_parameter' => '_password',

src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Security\Http\Logout;
1313

14-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
15-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1614
use Symfony\Component\HttpFoundation\RequestStack;
1715
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1816
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -47,14 +45,8 @@ public function __construct(RequestStack $requestStack = null, UrlGeneratorInter
4745
* @param string $csrfParameter The CSRF token parameter name
4846
* @param CsrfTokenManagerInterface $csrfTokenManager A CsrfTokenManagerInterface instance
4947
*/
50-
public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter, $csrfTokenManager = null)
48+
public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter, CsrfTokenManagerInterface $csrfTokenManager = null)
5149
{
52-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
53-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
54-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
55-
throw new \InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
56-
}
57-
5850
$this->listeners[$key] = array($logoutPath, $csrfTokenId, $csrfParameter, $csrfTokenManager);
5951
}
6052

0 commit comments

Comments
 (0)