diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f9b7621..af86422 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -35,7 +35,7 @@ jobs: fail-fast: false matrix: include: - - description: 'Symfony 6.0' + - description: 'Symfony 6.4' php: '8.1' composer_option: '--prefer-lowest' max_deprecations: 0 @@ -43,13 +43,17 @@ jobs: php: '8.2' symfony: 6.4.* max_deprecations: 0 - - description: 'Symfony 7.3' + - description: 'Symfony 7.4' php: '8.3' - symfony: 7.3.* + symfony: 7.4.* max_deprecations: 0 - description: 'Symfony 8.0' php: '8.4' - symfony: 8.0.*@dev + symfony: 8.0.* + max_deprecations: 0 + - description: 'Symfony 8.1' + php: '8.5' + symfony: 8.1.*@dev max_deprecations: 0 name: PHP ${{ matrix.php }} tests (${{ matrix.description }}) steps: diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 39737ad..5ff82b8 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -2,7 +2,7 @@ // see https://github.com/FriendsOfPHP/PHP-CS-Fixer $finder = PhpCsFixer\Finder::create() - ->in([__DIR__.'/src', __DIR__.'/tests']) + ->in([__DIR__.'/config', __DIR__.'/src', __DIR__.'/tests']) ; return (new PhpCsFixer\Config()) @@ -10,10 +10,10 @@ ->setRules([ '@Symfony' => true, '@Symfony:risky' => true, - '@PHP80Migration:risky' => true, - '@PHPUnit84Migration:risky' => true, + '@PHP8x0Migration:risky' => true, + '@PHPUnit8x4Migration:risky' => true, 'declare_strict_types' => false, - 'native_function_invocation' => ['include' => ['@all']], + 'native_function_invocation' => ['include' => ['@internal']], ]) ->setFinder($finder) ; diff --git a/composer.json b/composer.json index 5e0fe9c..1a37065 100644 --- a/composer.json +++ b/composer.json @@ -18,16 +18,16 @@ "require": { "php": "^8.1", "google/recaptcha": "^1.3", - "symfony/config": "^6.0 || ^7.0 || ^8.0", - "symfony/dependency-injection": "^6.0 || ^7.0 || ^8.0", - "symfony/form": "^6.0 || ^7.0 || ^8.0", - "symfony/http-kernel": "^6.0 || ^7.0 || ^8.0", - "symfony/validator": "^6.0 || ^7.0 || ^8.0" + "symfony/config": "^6.4 || ^7.4 || ^8.0", + "symfony/dependency-injection": "^6.4 || ^7.4 || ^8.0", + "symfony/form": "^6.4 || ^7.4 || ^8.0", + "symfony/http-kernel": "^6.4 || ^7.4 || ^8.0", + "symfony/validator": "^6.4 || ^7.4 || ^8.0" }, "require-dev": { "phpunit/phpunit": "^9.6", "symfony/http-client-contracts": "^3.5", - "symfony/phpunit-bridge": "^7.3" + "symfony/phpunit-bridge": "^7.4" }, "suggest": { "symfony/twig-bundle": "To render widget. Minimum supported Twig version is 2.4" diff --git a/config/services.php b/config/services.php new file mode 100644 index 0000000..9f08fa2 --- /dev/null +++ b/config/services.php @@ -0,0 +1,59 @@ +services(); + + $services + ->set('beelab_recaptcha2.google_recaptcha', ReCaptcha::class) + ->args([ + '%beelab_recaptcha2.secret%', + null, // placeholder is replaced by RequestMethodPass + ]) + ; + + $services + ->set(SymfonyClientRequestMethod::class) + ->call('setClient', [service(HttpClientInterface::class)->nullOnInvalid()]) + ; + + $services + ->set('beelab_recaptcha2.type', RecaptchaType::class) + ->public() + ->args(['%beelab_recaptcha2.site_key%']) + ->tag('form.type', ['alias' => 'beelab_recaptcha2']) + ; + + $services + ->set('beelab_recaptcha2.submit_type', RecaptchaSubmitType::class) + ->public() + ->args(['%beelab_recaptcha2.site_key%']) + ->tag('form.type', ['alias' => 'beelab_recaptcha2_submit']) + ; + + $services + ->set('beelab_recaptcha2.verifier', RecaptchaVerifier::class) + ->args([ + service('beelab_recaptcha2.google_recaptcha'), + service('request_stack'), + '%beelab_recaptcha2.enabled%', + ]) + ; + + $services + ->set('beelab_recaptcha2.validator', Recaptcha2Validator::class) + ->public() + ->args([service('beelab_recaptcha2.verifier')]) + ->tag('validator.constraint_validator', ['alias' => 'recaptcha2']) + ; +}; diff --git a/config/services.xml b/config/services.xml deleted file mode 100644 index ce3c41c..0000000 --- a/config/services.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - %beelab_recaptcha2.secret% - - - - - - - - - %beelab_recaptcha2.site_key% - - - - %beelab_recaptcha2.site_key% - - - - - - %beelab_recaptcha2.enabled% - - - - - - - - diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ec2fd12..e69de29 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,7 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" - count: 1 - path: src/DependencyInjection/Configuration.php - diff --git a/phpstan.neon b/phpstan.neon index 4198b7d..9365c9d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,7 @@ parameters: level: 6 paths: + - config - src - tests includes: diff --git a/src/DependencyInjection/BeelabRecaptcha2Extension.php b/src/DependencyInjection/BeelabRecaptcha2Extension.php index 7f7d1ee..3c3e6ca 100644 --- a/src/DependencyInjection/BeelabRecaptcha2Extension.php +++ b/src/DependencyInjection/BeelabRecaptcha2Extension.php @@ -23,8 +23,8 @@ public function load(array $configs, ContainerBuilder $container): void $requestMethodClass = $this->getRequestMethod($config['request_method']); $container->setParameter('beelab_recaptcha2.request_method', $requestMethodClass); - $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../../config')); - $loader->load('services.xml'); + $loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../../config')); + $loader->load('services.php'); } private function getRequestMethod(string $requestMethod): string diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 714e24e..dc27afd 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -11,7 +11,7 @@ public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('beelab_recaptcha2'); $rootNode = $treeBuilder->getRootNode(); - $rootNode + $rootNode // @phpstan-ignore-line method.notFound ->children() ->enumNode('request_method') ->values(['curl_post', 'post', 'http_client'])