Skip to content

Commit 31c4236

Browse files
author
alulord
committed
Bump versions for PHP 8.4 and Symfony 7 support
1 parent 2510c9d commit 31c4236

31 files changed

+2736
-4219
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class Configuration implements ConfigurationInterface
99
{
10-
public function getConfigTreeBuilder()
10+
public function getConfigTreeBuilder(): TreeBuilder
1111
{
1212
$treeBuilder = new TreeBuilder('omnipay');
1313
$rootNode = $treeBuilder->getRootNode();

DependencyInjection/OmnipayExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public function load(array $configs, ContainerBuilder $container)
1515
$configuration = new Configuration();
1616
$config = $this->processConfiguration($configuration, $configs);
1717

18-
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
19-
$loader->load('services.yaml');
18+
$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
19+
$loader->load('services.php');
2020

2121
$gateways = $config['gateways'];
2222
$gatewayNames = array_keys($gateways);

Manager/OmnipayManager.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@
1010

1111
class OmnipayManager
1212
{
13-
/**
14-
* @var GatewayFactory
15-
*/
16-
protected GatewayFactory $gatewayFactory;
17-
18-
/**
19-
* @var array
20-
*/
21-
protected array $config;
22-
2313
/**
2414
* @var GatewayInterface[]
2515
*/
@@ -45,10 +35,8 @@ class OmnipayManager
4535
*/
4636
protected bool $initOnBoot = false;
4737

48-
public function __construct(GatewayFactory $gatewayFactory, array $config = [])
38+
public function __construct(protected GatewayFactory $gatewayFactory, protected array $config = [])
4939
{
50-
$this->gatewayFactory = $gatewayFactory;
51-
$this->config = $config;
5240
}
5341

5442
public function get(string $gatewayName): GatewayInterface
@@ -79,7 +67,7 @@ protected function getGatewayConfig(string $gatewayName): array
7967

8068
public function registerGateway(GatewayInterface $gatewayInstance, ?string $alias = null): void
8169
{
82-
$name = $alias ?? Helper::getGatewayClassName(get_class($gatewayInstance));
70+
$name = $alias ?? Helper::getGatewayClassName($gatewayInstance::class);
8371

8472
if (in_array($name, $this->disabledGateways, true)) {
8573
return;

README.md

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ You can then use these gateways like usual.
4141

4242
## Configuration
4343

44-
Create config file `./config/packages/omnipay.yaml` or copy-paste from [example](config.example.yaml).<br>
44+
Create config file `./config/packages/omnipay.php` or copy-paste from [example](config.example.php).<br>
4545
Gateways can be configured in this file, i.e.:
4646

4747
``` yml
@@ -76,20 +76,23 @@ The configuration settings vary per gateway - see
7676

7777
Custom gateways can be registered via the container by tagging them with `omnipay.gateway`:
7878

79-
```yml
80-
# services.yaml
81-
services:
82-
my.custom.gateway:
83-
class: Path\To\CustomGateway
84-
tags:
85-
- { name: omnipay.gateway, alias: CustomGateway }
86-
87-
# omnipay.yaml
88-
omnipay:
89-
methods:
90-
# Reference the gateway alias here
91-
CustomGateway:
92-
apiKey: pa$$w0rd
79+
```php
80+
# services.php
81+
$services = $containerConfigurator->services();
82+
83+
$services->set('my.custom.gateway', 'Path\To\CustomGateway')
84+
->tag('omnipay.gateway', [
85+
'alias' => 'CustomGateway',
86+
]);
87+
88+
# omnipay.php
89+
$containerConfigurator->extension('omnipay', [
90+
'methods' => [
91+
'CustomGateway' => [
92+
'apiKey' => 'pa$$w0rd',
93+
],
94+
],
95+
]);
9396
```
9497

9598
You can then obtain the fully-configured gateway by its alias:
@@ -108,16 +111,19 @@ private function getCustomGateway(OmnipayManager $omnipay): GatewayInteface
108111
### Default gateway
109112

110113
Add default gateway key to your config:
111-
```yml
112-
# omnipay.yaml
113-
omnipay:
114-
gateways:
115-
MyGateway1:
116-
apiKey: pa$$w0rd
117-
MyGateway2:
118-
apiKey: pa$$w0rd
119-
120-
default: MyGateway1
114+
```php
115+
# omnipay.php
116+
$containerConfigurator->extension('omnipay', [
117+
'gateways' => [
118+
'MyGateway1' => [
119+
'apiKey' => 'pa$$w0rd',
120+
],
121+
'MyGateway2' => [
122+
'apiKey' => 'pa$$w0rd',
123+
],
124+
],
125+
'default' => 'MyGateway1',
126+
]);
121127
```
122128

123129
You can now get default gateway instance:
@@ -128,16 +134,21 @@ $omnipay->getDefaultGateway();
128134
### Disabling gateways
129135

130136
If need to disable a gateway but want to keep all the configuration add `disabled` key to the config:
131-
```yml
132-
# omnipay.yaml
133-
omnipay:
134-
gateways:
135-
MyGateway1:
136-
apiKey: pa$$w0rd
137-
MyGateway2:
138-
apiKey: pa$$w0rd
139-
140-
disabled: [ MyGateway1 ]
137+
```php
138+
# omnipay.php
139+
$containerConfigurator->extension('omnipay', [
140+
'gateways' => [
141+
'MyGateway1' => [
142+
'apiKey' => 'pa$$w0rd',
143+
],
144+
'MyGateway2' => [
145+
'apiKey' => 'pa$$w0rd',
146+
],
147+
],
148+
'disabled' => [
149+
'MyGateway1',
150+
],
151+
]);
141152
```
142153

143154
`MyGateway1` gateway will be skipped during gateway registration now.
@@ -211,4 +222,4 @@ $ phpunit
211222
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
212223
## License
213224

214-
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
225+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Resources/config/services.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Janwebdev\OmnipayBundle\Manager\OmnipayManager;
6+
use Omnipay\Common\GatewayFactory;
7+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
8+
9+
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
10+
11+
return static function (ContainerConfigurator $containerConfigurator): void {
12+
$parameters = $containerConfigurator->parameters();
13+
14+
$parameters->set('omnipay.class', OmnipayManager::class);
15+
16+
$services = $containerConfigurator->services();
17+
18+
$services->set('omnipay', '%omnipay.class%')
19+
->args([
20+
service('omnipay.factory'),
21+
]);
22+
23+
$services->set('omnipay.factory', GatewayFactory::class)
24+
->private();
25+
};

Resources/config/services.yaml

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

Tests/DependencyInjection/Compiler/GatewayTagCompilerPassTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testProcessWithAlias(): void
3535
$methodCalls = $this->getMethodCallsByName($omnipayDefinition, 'registerGateway');
3636
$this->assertCount(1, $methodCalls);
3737

38-
list($reference, $alias) = reset($methodCalls);
38+
[$reference, $alias] = reset($methodCalls);
3939
$this->assertReferenceEquals('test.gateway', $reference);
4040
$this->assertEquals('TestGateway', $alias);
4141
}
@@ -52,7 +52,7 @@ public function testProcessWithoutAlias(): void
5252
$methodCalls = $this->getMethodCallsByName($omnipayDefinition, 'registerGateway');
5353
$this->assertCount(1, $methodCalls);
5454

55-
list($reference) = reset($methodCalls);
55+
[$reference] = reset($methodCalls);
5656
$this->assertReferenceEquals('test.gateway', $reference);
5757
}
5858

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
6+
7+
return static function (ContainerConfigurator $containerConfigurator): void {
8+
$containerConfigurator->extension('omnipay', []);
9+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
6+
7+
return static function (ContainerConfigurator $containerConfigurator): void {
8+
$containerConfigurator->extension('omnipay', [
9+
'methods' => [
10+
'Stripe' => [
11+
'apiKey' => 'sk_test_BQokikJOvBiI2HlWgH4olfQ2',
12+
],
13+
'PayPal_Express' => [
14+
'username' => 'test-facilitator_api1.example.com',
15+
'password' => '3MPI3VB4NVQ3XSVF',
16+
'signature' => '6fB0XmM3ODhbVdfev2hUXL2x7QWxXlb1dERTKhtWaABmpiCK1wtfcWd.',
17+
'testMode' => false,
18+
'solutionType' => 'Sole',
19+
'landingPage' => 'Login',
20+
],
21+
],
22+
'disabled_gateways' => [
23+
'Stripe',
24+
],
25+
'default_gateway' => 'Stripe',
26+
]);
27+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
6+
7+
return static function (ContainerConfigurator $containerConfigurator): void {
8+
$containerConfigurator->extension('omnipay', [
9+
'gateways' => [
10+
'Stripe' => [
11+
'apiKey' => 'sk_test_BQokikJOvBiI2HlWgH4olfQ2',
12+
],
13+
'PayPal_Express' => [
14+
'username' => 'test-facilitator_api1.example.com',
15+
'password' => '3MPI3VB4NVQ3XSVF',
16+
'signature' => '6fB0XmM3ODhbVdfev2hUXL2x7QWxXlb1dERTKhtWaABmpiCK1wtfcWd.',
17+
'testMode' => false,
18+
'solutionType' => 'Sole',
19+
'landingPage' => 'Login',
20+
],
21+
],
22+
'default' => 'Stripe',
23+
'disabled' => [
24+
'PayPal_Express',
25+
],
26+
]);
27+
};

0 commit comments

Comments
 (0)