From 46e9fa145cd789957584f0c142bad4c703bf10fe Mon Sep 17 00:00:00 2001 From: snipershady Date: Fri, 29 Dec 2023 17:38:36 +0000 Subject: [PATCH 01/11] Update support to Symfony7 --- .github/workflows/build.yml | 10 ++++++++-- .gitignore | 1 + composer.json | 10 +++++----- nbproject/project.properties | 7 +++++++ nbproject/project.xml | 9 +++++++++ src/DependencyInjection/Configuration.php | 4 ++-- .../EWZRecaptchaExtension.php | 7 ++++++- .../ReCaptcha/RequestMethod/Post.php | 14 ++++++------- .../ReCaptcha/RequestMethod/ProxyPost.php | 16 +++++++-------- .../EWZRecaptchaV2FormBuilderFactory.php | 12 +++++------ .../EWZRecaptchaV3FormBuilderFactory.php | 13 ++++++------ src/Form/Type/AbstractEWZRecaptchaType.php | 8 ++++---- src/Form/Type/EWZRecaptchaType.php | 11 +++++----- src/Form/Type/EWZRecaptchaV3Type.php | 5 +++-- src/Locale/LocaleResolver.php | 6 +++--- .../views/Form/ewz_recaptcha_widget.html.php | 8 ++++---- .../views/Form/ewz_recaptcha_widget.html.twig | 8 ++++---- src/Validator/Constraints/IsTrue.php | 2 +- src/Validator/Constraints/IsTrueValidator.php | 15 +++++++------- .../Constraints/IsTrueValidatorV3.php | 20 ++++++++++--------- 20 files changed, 110 insertions(+), 76 deletions(-) create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f954f79..bd0c451 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,13 +14,19 @@ jobs: strategy: fail-fast: true matrix: - php: [7.1, 7.2, 7.3, 7.4, 8.0, 8.1] - symfony: [2.8, 3.4, 4.4, 5.2, 6.0] + php: [7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2] + symfony: [2.8, 3.4, 4.4, 5.2, 6.0, 7.0] exclude: - php: 7.1 symfony: 5.2 - php: 8.0 symfony: 3.4 + - php: 8.1 + symfony: 3.4 + - php: 8.2 + symfony: 3.4 + - php: 8.3 + symfony: 3.4 - php: 7.1 symfony: 6.0 - php: 7.2 diff --git a/.gitignore b/.gitignore index f57301d..f248fec 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ phpunit.xml vendor/ composer.lock +/nbproject/private/ diff --git a/composer.json b/composer.json index a45a77e..e946dc4 100644 --- a/composer.json +++ b/composer.json @@ -17,11 +17,11 @@ "require": { "php": "^7.1 || ^8.0", "google/recaptcha": "^1.1", - "symfony/form": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0", - "symfony/framework-bundle": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0", - "symfony/security-bundle": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0", - "symfony/validator": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0", - "symfony/yaml": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0", + "symfony/form": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/framework-bundle": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/security-bundle": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/validator": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/yaml": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0", "twig/twig": "^1.40 || ^2.9 || ^3.0" }, "require-dev": { diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..cc0417d --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_82 +source.encoding=UTF-8 +src.dir=. +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..41bc723 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + EWZRecaptchaBundle + + + diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index f5ecb03..e43b592 100755 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -51,7 +51,7 @@ public function getConfigTreeBuilder(): TreeBuilder return $treeBuilder; } - private function addHttpClientConfiguration(ArrayNodeDefinition $node) + private function addHttpClientConfiguration(ArrayNodeDefinition $node): void { $node ->children() @@ -67,7 +67,7 @@ private function addHttpClientConfiguration(ArrayNodeDefinition $node) ; } - private function addServiceDefinitionConfiguration(ArrayNodeDefinition $node) + private function addServiceDefinitionConfiguration(ArrayNodeDefinition $node): void { $node ->children() diff --git a/src/DependencyInjection/EWZRecaptchaExtension.php b/src/DependencyInjection/EWZRecaptchaExtension.php index c1489ba..1c661ed 100755 --- a/src/DependencyInjection/EWZRecaptchaExtension.php +++ b/src/DependencyInjection/EWZRecaptchaExtension.php @@ -89,7 +89,12 @@ protected function registerWidget(ContainerBuilder $container, int $version = 2) } } - private function getTwigFormResources(ContainerBuilder $container) + /** + * + * @param ContainerBuilder $container + * @return array|string|false + */ + private function getTwigFormResources(ContainerBuilder $container): array|string|false { if (!$container->hasParameter('twig.form.resources')) { return []; diff --git a/src/Extension/ReCaptcha/RequestMethod/Post.php b/src/Extension/ReCaptcha/RequestMethod/Post.php index dae3aa5..f4caac9 100644 --- a/src/Extension/ReCaptcha/RequestMethod/Post.php +++ b/src/Extension/ReCaptcha/RequestMethod/Post.php @@ -15,17 +15,17 @@ class Post implements RequestMethod * * @var string */ - private $recaptchaVerifyUrl; + private string $recaptchaVerifyUrl; /** * The timeout for the reCAPTCHA verification. * * @var int|null */ - private $timeout; + private ?int $timeout; /** @var array */ - private $cache; + private array $cache; /** * Constructor. @@ -59,8 +59,8 @@ public function submit(RequestParameters $params): string * Using "CN_name" will still work, but it will raise deprecated errors. */ $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; - $options = array( - 'http' => array( + $options = [ + 'http' => [ 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => $params->toQueryString(), @@ -68,8 +68,8 @@ public function submit(RequestParameters $params): string 'verify_peer' => true, // Force the peer validation to use www.google.com $peer_key => 'www.google.com', - ), - ); + ], + ]; if (null !== $this->timeout) { $options['http']['timeout'] = $this->timeout; } diff --git a/src/Extension/ReCaptcha/RequestMethod/ProxyPost.php b/src/Extension/ReCaptcha/RequestMethod/ProxyPost.php index 2017baa..fb1cae8 100644 --- a/src/Extension/ReCaptcha/RequestMethod/ProxyPost.php +++ b/src/Extension/ReCaptcha/RequestMethod/ProxyPost.php @@ -15,24 +15,24 @@ class ProxyPost implements RequestMethod * * @var array */ - private $httpProxy; + private array $httpProxy; /** * The reCAPTCHA verify server URL. * * @var string */ - private $recaptchaVerifyUrl; + private string $recaptchaVerifyUrl; /** * The timeout for the reCAPTCHA verification. * * @var int|null */ - private $timeout; + private ?int $timeout; /** @var array */ - private $cache; + private array $cache; /** * Constructor. @@ -72,8 +72,8 @@ public function submit(RequestParameters $params): string * Using "CN_name" will still work, but it will raise deprecated errors. */ $peerKey = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; - $options = array( - 'http' => array( + $options = [ + 'http' => [ 'header' => sprintf("Content-type: application/x-www-form-urlencoded\r\n%s", $proxyAuth), 'method' => 'POST', 'content' => $params->toQueryString(), @@ -85,8 +85,8 @@ public function submit(RequestParameters $params): string 'proxy' => sprintf('tcp://%s:%s', $this->httpProxy['host'], $this->httpProxy['port']), // While this is a non-standard request format, some proxy servers require it. 'request_fulluri' => true, - ), - ); + ], + ]; if (null !== $this->timeout) { $options['http']['timeout'] = $this->timeout; } diff --git a/src/Factory/EWZRecaptchaV2FormBuilderFactory.php b/src/Factory/EWZRecaptchaV2FormBuilderFactory.php index 1ba210e..5a56a5b 100755 --- a/src/Factory/EWZRecaptchaV2FormBuilderFactory.php +++ b/src/Factory/EWZRecaptchaV2FormBuilderFactory.php @@ -8,20 +8,20 @@ class EWZRecaptchaV2FormBuilderFactory { - private $builder; + private FormFactoryInterface $builder; public function __construct(FormFactoryInterface $builder) { $this->builder = $builder; } - public function get(array $options = array()) + public function get(array $options = array()) :FormBuilderInterface { - $constraint = array( - 'constraints' => array( + $constraint = [ + 'constraints' => [ new IsTrue(), - ), - ); + ], + ]; return $this->builder->createBuilder(EWZRecaptchaType::class, null, array_merge($options, $constraint)); } diff --git a/src/Factory/EWZRecaptchaV3FormBuilderFactory.php b/src/Factory/EWZRecaptchaV3FormBuilderFactory.php index 890de8e..394301b 100755 --- a/src/Factory/EWZRecaptchaV3FormBuilderFactory.php +++ b/src/Factory/EWZRecaptchaV3FormBuilderFactory.php @@ -5,23 +5,24 @@ use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaV3Type; use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrueV3; use Symfony\Component\Form\FormFactoryInterface; +use Symfony\Component\Form\FormBuilderInterface; class EWZRecaptchaV3FormBuilderFactory { - private $builder; + private FormFactoryInterface $builder; public function __construct(FormFactoryInterface $builder) { $this->builder = $builder; } - public function get(array $options = array()) + public function get(array $options = array()) :FormBuilderInterface { - $constraint = array( - 'constraints' => array( + $constraint = [ + 'constraints' => [ new IsTrueV3(), - ), - ); + ], + ]; return $this->builder->createBuilder(EWZRecaptchaV3Type::class, null, array_merge($options, $constraint)); } diff --git a/src/Form/Type/AbstractEWZRecaptchaType.php b/src/Form/Type/AbstractEWZRecaptchaType.php index c0ef48e..de47403 100755 --- a/src/Form/Type/AbstractEWZRecaptchaType.php +++ b/src/Form/Type/AbstractEWZRecaptchaType.php @@ -13,28 +13,28 @@ abstract class AbstractEWZRecaptchaType extends AbstractType * * @var string */ - protected $publicKey; + protected string $publicKey; /** * Enable recaptcha? * * @var bool */ - protected $enabled; + protected bool $enabled; /** * The API server host name. * * @var string */ - protected $apiHost; + protected string $apiHost; /** * The reCAPTCHA server URL. * * @var string */ - protected $recaptchaApiServer; + protected string $recaptchaApiServer; /** * @param string $publicKey Recaptcha public key diff --git a/src/Form/Type/EWZRecaptchaType.php b/src/Form/Type/EWZRecaptchaType.php index b5672d8..90a80fe 100755 --- a/src/Form/Type/EWZRecaptchaType.php +++ b/src/Form/Type/EWZRecaptchaType.php @@ -18,10 +18,10 @@ class EWZRecaptchaType extends AbstractEWZRecaptchaType * * @var bool */ - protected $ajax; + protected bool $ajax; /** @var LocaleResolver */ - protected $localeResolver; + protected LocaleResolver $localeResolver; /** * @param string $publicKey Recaptcha public key @@ -42,7 +42,8 @@ public function __construct(string $publicKey, bool $enabled, bool $ajax, Locale */ public function configureOptions(OptionsResolver $resolver): void { - $resolver->setDefaults(array( + $resolver->setDefaults( + [ 'compound' => false, 'language' => $this->localeResolver->resolve(), 'public_key' => null, @@ -61,7 +62,7 @@ public function configureOptions(OptionsResolver $resolver): void 'badge' => null, ), ), - )); + ]); } /** @@ -79,7 +80,7 @@ public function getParent(): string * * @return string The javascript source URL */ - public function getScriptURL($key) + public function getScriptURL(string $key): ?string { return isset($this->scripts[$key]) ? $this->scripts[$key] : null; } diff --git a/src/Form/Type/EWZRecaptchaV3Type.php b/src/Form/Type/EWZRecaptchaV3Type.php index 989a728..5e9ac4e 100755 --- a/src/Form/Type/EWZRecaptchaV3Type.php +++ b/src/Form/Type/EWZRecaptchaV3Type.php @@ -12,7 +12,7 @@ class EWZRecaptchaV3Type extends AbstractEWZRecaptchaType public const DEFAULT_ACTION_NAME = 'form'; /** @var bool */ - private $hideBadge; + private bool $hideBadge; /** * EWZRecaptchaV3Type constructor. @@ -47,7 +47,8 @@ public function configureOptions(OptionsResolver $resolver): void } /** - * {@inheritdoc} + * + * @return string */ public function getParent(): string { diff --git a/src/Locale/LocaleResolver.php b/src/Locale/LocaleResolver.php index ede7097..b717458 100644 --- a/src/Locale/LocaleResolver.php +++ b/src/Locale/LocaleResolver.php @@ -10,13 +10,13 @@ final class LocaleResolver { /** @var string */ - private $defaultLocale; + private string $defaultLocale; /** @var bool */ - private $useLocaleFromRequest; + private bool $useLocaleFromRequest; /** @var RequestStack */ - private $requestStack; + private RequestStack $requestStack; /** * @param string $defaultLocale diff --git a/src/Resources/views/Form/ewz_recaptcha_widget.html.php b/src/Resources/views/Form/ewz_recaptcha_widget.html.php index 6c6eff3..dec5c4a 100644 --- a/src/Resources/views/Form/ewz_recaptcha_widget.html.php +++ b/src/Resources/views/Form/ewz_recaptcha_widget.html.php @@ -5,19 +5,19 @@