diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f954f79..1229efd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,21 +14,39 @@ 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: 7.1 symfony: 6.0 + - php: 7.1 + symfony: 7.0 - php: 7.2 symfony: 6.0 + - php: 7.2 + symfony: 7.0 - php: 7.3 symfony: 6.0 + - php: 7.3 + symfony: 7.0 - php: 7.4 symfony: 6.0 + - php: 7.4 + symfony: 7.0 + - php: 8.0 + symfony: 3.4 + - php: 8.0 + symfony: 7.0 + - php: 8.1 + symfony: 3.4 + - php: 8.1 + symfony: 7.0 + - php: 8.2 + symfony: 3.4 + - php: 8.3 + symfony: 3.4 steps: - name: Checkout uses: actions/checkout@v2 diff --git a/.gitignore b/.gitignore index f57301d..15bdca2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ phpunit.xml vendor/ composer.lock +/nbproject/ diff --git a/README.md b/README.md index f3db8dc..ecaf60f 100755 --- a/README.md +++ b/README.md @@ -4,6 +4,11 @@ EWZRecaptchaBundle [![Actions Status](https://github.com/excelwebzone/EWZRecaptchaBundle/workflows/CI/badge.svg)](https://github.com/excelwebzone/EWZRecaptchaBundle/actions) This bundle provides easy reCAPTCHA form field for Symfony. +This is a fork of excelwebzone/EWZRecaptchaBundle compliant with Symfony 7.0 requirements. + +## Changelog +29-12-2023: updated compatibilty with symfony 7.0 +29-12-2023: fix some minor bugs. ## Installation diff --git a/composer.json b/composer.json index a45a77e..e0d5cef 100644 --- a/composer.json +++ b/composer.json @@ -42,4 +42,4 @@ "allow-contrib": "true" } } -} +} \ No newline at end of file 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..9d5919a 100755 --- a/src/DependencyInjection/EWZRecaptchaExtension.php +++ b/src/DependencyInjection/EWZRecaptchaExtension.php @@ -67,7 +67,7 @@ protected function registerWidget(ContainerBuilder $container, int $version = 2) ? $container->getParameter('templating.engines') : array('twig'); - if (in_array('php', $templatingEngines, true)) { + if (is_array($templatingEngines) && in_array('php', $templatingEngines, true)) { $formResource = 'EWZRecaptchaBundle:Form'; $container->setParameter('templating.helper.form.resources', array_merge( @@ -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..521741b 100644 --- a/src/Extension/ReCaptcha/RequestMethod/Post.php +++ b/src/Extension/ReCaptcha/RequestMethod/Post.php @@ -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..4afdbf4 100644 --- a/src/Extension/ReCaptcha/RequestMethod/ProxyPost.php +++ b/src/Extension/ReCaptcha/RequestMethod/ProxyPost.php @@ -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..f5c6d2e 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 = []) :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..058a5c1 100755 --- a/src/Form/Type/EWZRecaptchaType.php +++ b/src/Form/Type/EWZRecaptchaType.php @@ -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,11 +62,12 @@ public function configureOptions(OptionsResolver $resolver): void 'badge' => null, ), ), - )); + ]); } /** - * {@inheritdoc} + * + * @return string */ public function getParent(): string { @@ -79,7 +81,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; } @@ -89,22 +91,22 @@ public function getScriptURL($key) */ protected function addCustomVars(FormView $view, FormInterface $form, array $options): void { - $view->vars = array_replace($view->vars, array( + $view->vars = array_replace($view->vars, [ 'ewz_recaptcha_ajax' => $this->ajax, - )); + ]); if (!isset($options['language'])) { $options['language'] = $this->localeResolver->resolve(); } if (!$this->ajax) { - $view->vars = array_replace($view->vars, array( + $view->vars = array_replace($view->vars, [ 'url_challenge' => sprintf('%s?hl=%s', $this->recaptchaApiServer, $options['language']), - )); + ]); } else { - $view->vars = array_replace($view->vars, array( + $view->vars = array_replace($view->vars, [ 'url_api' => sprintf('//%s/recaptcha/api/js/recaptcha_ajax.js', $this->apiHost), - )); + ]); } } } diff --git a/src/Form/Type/EWZRecaptchaV3Type.php b/src/Form/Type/EWZRecaptchaV3Type.php index 989a728..fc0107d 100755 --- a/src/Form/Type/EWZRecaptchaV3Type.php +++ b/src/Form/Type/EWZRecaptchaV3Type.php @@ -47,7 +47,8 @@ public function configureOptions(OptionsResolver $resolver): void } /** - * {@inheritdoc} + * + * @return string */ public function getParent(): string { 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 @@