Skip to content

Commit c8c06ba

Browse files
authored
Merge pull request #68 from Bee-Lab/php-config
🔧 convert configuration to PHP
2 parents 0b83dd9 + 32be6c3 commit c8c06ba

File tree

9 files changed

+81
-60
lines changed

9 files changed

+81
-60
lines changed

.github/workflows/build.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,25 @@ jobs:
3535
fail-fast: false
3636
matrix:
3737
include:
38-
- description: 'Symfony 6.0'
38+
- description: 'Symfony 6.4'
3939
php: '8.1'
4040
composer_option: '--prefer-lowest'
4141
max_deprecations: 0
4242
- description: 'Symfony 6.4'
4343
php: '8.2'
4444
symfony: 6.4.*
4545
max_deprecations: 0
46-
- description: 'Symfony 7.3'
46+
- description: 'Symfony 7.4'
4747
php: '8.3'
48-
symfony: 7.3.*
48+
symfony: 7.4.*
4949
max_deprecations: 0
5050
- description: 'Symfony 8.0'
5151
php: '8.4'
52-
symfony: 8.0.*@dev
52+
symfony: 8.0.*
53+
max_deprecations: 0
54+
- description: 'Symfony 8.1'
55+
php: '8.5'
56+
symfony: 8.1.*@dev
5357
max_deprecations: 0
5458
name: PHP ${{ matrix.php }} tests (${{ matrix.description }})
5559
steps:

.php-cs-fixer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
// see https://github.com/FriendsOfPHP/PHP-CS-Fixer
33

44
$finder = PhpCsFixer\Finder::create()
5-
->in([__DIR__.'/src', __DIR__.'/tests'])
5+
->in([__DIR__.'/config', __DIR__.'/src', __DIR__.'/tests'])
66
;
77

88
return (new PhpCsFixer\Config())
99
->setRiskyAllowed(true)
1010
->setRules([
1111
'@Symfony' => true,
1212
'@Symfony:risky' => true,
13-
'@PHP80Migration:risky' => true,
14-
'@PHPUnit84Migration:risky' => true,
13+
'@PHP8x0Migration:risky' => true,
14+
'@PHPUnit8x4Migration:risky' => true,
1515
'declare_strict_types' => false,
16-
'native_function_invocation' => ['include' => ['@all']],
16+
'native_function_invocation' => ['include' => ['@internal']],
1717
])
1818
->setFinder($finder)
1919
;

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
"require": {
1919
"php": "^8.1",
2020
"google/recaptcha": "^1.3",
21-
"symfony/config": "^6.0 || ^7.0 || ^8.0",
22-
"symfony/dependency-injection": "^6.0 || ^7.0 || ^8.0",
23-
"symfony/form": "^6.0 || ^7.0 || ^8.0",
24-
"symfony/http-kernel": "^6.0 || ^7.0 || ^8.0",
25-
"symfony/validator": "^6.0 || ^7.0 || ^8.0"
21+
"symfony/config": "^6.4 || ^7.4 || ^8.0",
22+
"symfony/dependency-injection": "^6.4 || ^7.4 || ^8.0",
23+
"symfony/form": "^6.4 || ^7.4 || ^8.0",
24+
"symfony/http-kernel": "^6.4 || ^7.4 || ^8.0",
25+
"symfony/validator": "^6.4 || ^7.4 || ^8.0"
2626
},
2727
"require-dev": {
2828
"phpunit/phpunit": "^9.6",
2929
"symfony/http-client-contracts": "^3.5",
30-
"symfony/phpunit-bridge": "^7.3"
30+
"symfony/phpunit-bridge": "^7.4"
3131
},
3232
"suggest": {
3333
"symfony/twig-bundle": "To render widget. Minimum supported Twig version is 2.4"

config/services.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
use Beelab\Recaptcha2Bundle\Form\Type\RecaptchaSubmitType;
4+
use Beelab\Recaptcha2Bundle\Form\Type\RecaptchaType;
5+
use Beelab\Recaptcha2Bundle\Recaptcha\RecaptchaVerifier;
6+
use Beelab\Recaptcha2Bundle\Recaptcha\SymfonyClientRequestMethod;
7+
use Beelab\Recaptcha2Bundle\Validator\Constraints\Recaptcha2Validator;
8+
use ReCaptcha\ReCaptcha;
9+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
10+
use Symfony\Contracts\HttpClient\HttpClientInterface;
11+
12+
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
13+
14+
return static function (ContainerConfigurator $configurator): void {
15+
$services = $configurator->services();
16+
17+
$services
18+
->set('beelab_recaptcha2.google_recaptcha', ReCaptcha::class)
19+
->args([
20+
'%beelab_recaptcha2.secret%',
21+
null, // placeholder is replaced by RequestMethodPass
22+
])
23+
;
24+
25+
$services
26+
->set(SymfonyClientRequestMethod::class)
27+
->call('setClient', [service(HttpClientInterface::class)->nullOnInvalid()])
28+
;
29+
30+
$services
31+
->set('beelab_recaptcha2.type', RecaptchaType::class)
32+
->public()
33+
->args(['%beelab_recaptcha2.site_key%'])
34+
->tag('form.type', ['alias' => 'beelab_recaptcha2'])
35+
;
36+
37+
$services
38+
->set('beelab_recaptcha2.submit_type', RecaptchaSubmitType::class)
39+
->public()
40+
->args(['%beelab_recaptcha2.site_key%'])
41+
->tag('form.type', ['alias' => 'beelab_recaptcha2_submit'])
42+
;
43+
44+
$services
45+
->set('beelab_recaptcha2.verifier', RecaptchaVerifier::class)
46+
->args([
47+
service('beelab_recaptcha2.google_recaptcha'),
48+
service('request_stack'),
49+
'%beelab_recaptcha2.enabled%',
50+
])
51+
;
52+
53+
$services
54+
->set('beelab_recaptcha2.validator', Recaptcha2Validator::class)
55+
->public()
56+
->args([service('beelab_recaptcha2.verifier')])
57+
->tag('validator.constraint_validator', ['alias' => 'recaptcha2'])
58+
;
59+
};

config/services.xml

Lines changed: 0 additions & 36 deletions
This file was deleted.

phpstan-baseline.neon

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
parameters:
2-
ignoreErrors:
3-
-
4-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#"
5-
count: 1
6-
path: src/DependencyInjection/Configuration.php
7-

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
parameters:
22
level: 6
33
paths:
4+
- config
45
- src
56
- tests
67
includes:

src/DependencyInjection/BeelabRecaptcha2Extension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public function load(array $configs, ContainerBuilder $container): void
2323
$requestMethodClass = $this->getRequestMethod($config['request_method']);
2424
$container->setParameter('beelab_recaptcha2.request_method', $requestMethodClass);
2525

26-
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
27-
$loader->load('services.xml');
26+
$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../../config'));
27+
$loader->load('services.php');
2828
}
2929

3030
private function getRequestMethod(string $requestMethod): string

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function getConfigTreeBuilder(): TreeBuilder
1111
{
1212
$treeBuilder = new TreeBuilder('beelab_recaptcha2');
1313
$rootNode = $treeBuilder->getRootNode();
14-
$rootNode
14+
$rootNode // @phpstan-ignore-line method.notFound
1515
->children()
1616
->enumNode('request_method')
1717
->values(['curl_post', 'post', 'http_client'])

0 commit comments

Comments
 (0)