Skip to content

Commit 4322a97

Browse files
authored
Merge pull request #541 from Chris53897/feature/support-symfony6
Feat: support symfony6
2 parents 14604f9 + 82b09f2 commit 4322a97

File tree

84 files changed

+588
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+588
-445
lines changed

.github/workflows/tests.yaml

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,31 @@ env:
77

88
jobs:
99
unit-test:
10-
name: Unit ( PHP ${{ matrix.php }} )
10+
name: Unit ( PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }} )
1111
runs-on: ubuntu-latest
1212

1313
strategy:
1414
fail-fast: false
1515
matrix:
1616
include:
1717
- php: 7.4
18+
symfony: 4.4.*
19+
- php: 7.4
20+
symfony: 5.4.*
21+
- php: 8.0
22+
symfony: 4.4.*
23+
- php: 8.0
24+
symfony: 5.4.*
1825
- php: 8.0
26+
symfony: 6.0.*
27+
- php: 8.1
28+
symfony: 4.4.*
29+
- php: 8.1
30+
symfony: 5.4.*
1931
- php: 8.1
32+
symfony: 6.0.*
33+
- php: 8.1
34+
symfony: 6.1.*
2035

2136
steps:
2237
- name: Checkout
@@ -39,45 +54,16 @@ jobs:
3954
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json composer.lock') }}
4055
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer-
4156

42-
- name: Install dependencies
43-
run: composer update
44-
45-
- name: Run unit tests
46-
run: bin/phpunit
47-
48-
lowest:
49-
name: Unit ( PHP ${{ matrix.php }} + Lowest )
50-
runs-on: ubuntu-latest
51-
52-
strategy:
53-
fail-fast: false
54-
matrix:
55-
include:
56-
- php: 7.4
57-
58-
steps:
59-
- name: Checkout
60-
uses: actions/checkout@v2
61-
62-
- name: Setup PHP
63-
uses: shivammathur/setup-php@v2
64-
with:
65-
php-version: ${{ matrix.php }}
66-
extensions: intl, opcache, mysql, pdo_mysql, :xdebug
67-
68-
- name: Get composer cache directory
69-
id: composercache
70-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
57+
- name: Install Symfony ${{ matrix.symfony }}
58+
run: composer config extra.symfony.require ${{ matrix.symfony }}
7159

72-
- name: Cache dependencies
73-
uses: actions/cache@v2
74-
with:
75-
path: ${{ steps.composercache.outputs.dir }}
76-
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json composer.lock') }}
77-
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer-
60+
- name: Install Symfony Flex
61+
run: |
62+
composer require symfony/flex:^1 --no-update
63+
composer config --no-plugins allow-plugins.symfony/flex true
7864
7965
- name: Install dependencies
80-
run: composer update --prefer-lowest --prefer-stable
66+
run: composer update
8167

8268
- name: Run unit tests
8369
run: bin/phpunit

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 2.5.0 (2022-07-xx)
4+
5+
* Support for Symfony 5.0 - 5.3 dropped
6+
* Added support for Symfony 6.0
7+
* Minimum Payum Core dependency updated to 1.7.2
8+
39
## 2.3.1 (2018-08-19)
410

511
* Make profiler dynamic

Command/CreateCaptureTokenCommand.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@
33

44
use Payum\Core\Exception\RuntimeException;
55
use Payum\Core\Payum;
6+
use Symfony\Component\Console\Attribute\AsCommand;
67
use Symfony\Component\Console\Command\Command;
78
use Symfony\Component\Console\Input\InputArgument;
89
use Symfony\Component\Console\Input\InputInterface;
910
use Symfony\Component\Console\Input\InputOption;
1011
use Symfony\Component\Console\Output\OutputInterface;
11-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
12-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
1312

14-
class CreateCaptureTokenCommand extends Command implements ContainerAwareInterface
13+
#[AsCommand(name: 'payum:security:create-capture-token')]
14+
class CreateCaptureTokenCommand extends Command
1515
{
16-
use ContainerAwareTrait;
17-
1816
protected static $defaultName = 'payum:security:create-capture-token';
1917

18+
private Payum $payum;
19+
20+
public function __construct(Payum $payum)
21+
{
22+
$this->payum = $payum;
23+
24+
parent::__construct();
25+
}
26+
2027
/**
2128
* {@inheritDoc}
2229
*/
@@ -43,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4350

4451
$model = null;
4552
if ($modelClass && $modelId) {
46-
if (false == $model = $this->getPayum()->getStorage($modelClass)->find($modelId)) {
53+
if (false === $model = $this->payum->getStorage($modelClass)->find($modelId)) {
4754
throw new RuntimeException(sprintf(
4855
'Cannot find model with class %s and id %s.',
4956
$modelClass,
@@ -52,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5259
}
5360
}
5461

55-
$token = $this->getPayum()->getTokenFactory()->createCaptureToken($gatewayName, $model, $afterUrl);
62+
$token = $this->payum->getTokenFactory()->createCaptureToken($gatewayName, $model, $afterUrl);
5663

5764
$output->writeln(sprintf('Hash: <info>%s</info>', $token->getHash()));
5865
$output->writeln(sprintf('Url: <info>%s</info>', $token->getTargetUrl()));
@@ -61,12 +68,4 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6168

6269
return 0;
6370
}
64-
65-
/**
66-
* @return Payum
67-
*/
68-
protected function getPayum()
69-
{
70-
return $this->container->get('payum');
71-
}
7271
}

Command/CreateNotifyTokenCommand.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@
33

44
use Payum\Core\Exception\RuntimeException;
55
use Payum\Core\Payum;
6+
use Symfony\Component\Console\Attribute\AsCommand;
67
use Symfony\Component\Console\Command\Command;
78
use Symfony\Component\Console\Input\InputArgument;
89
use Symfony\Component\Console\Input\InputInterface;
910
use Symfony\Component\Console\Input\InputOption;
1011
use Symfony\Component\Console\Output\OutputInterface;
11-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
12-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
1312

14-
class CreateNotifyTokenCommand extends Command implements ContainerAwareInterface
13+
#[AsCommand(name: 'payum:security:create-notify-token')]
14+
class CreateNotifyTokenCommand extends Command
1515
{
16-
use ContainerAwareTrait;
17-
1816
protected static $defaultName = 'payum:security:create-notify-token';
1917

18+
private Payum $payum;
19+
20+
public function __construct(Payum $payum)
21+
{
22+
$this->payum = $payum;
23+
24+
parent::__construct();
25+
}
26+
2027
/**
2128
* {@inheritDoc}
2229
*/
@@ -41,7 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4148
$model = null;
4249

4350
if ($modelClass && $modelId) {
44-
if (false == $model = $this->getPayum()->getStorage($modelClass)->find($modelId)) {
51+
if (false === $model = $this->payum->getStorage($modelClass)->find($modelId)) {
4552
throw new RuntimeException(sprintf(
4653
'Cannot find model with class %s and id %s.',
4754
$modelClass,
@@ -50,20 +57,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5057
}
5158
}
5259

53-
$token = $this->getPayum()->getTokenFactory()->createNotifyToken($gatewayName, $model);
60+
$token = $this->payum->getTokenFactory()->createNotifyToken($gatewayName, $model);
5461

5562
$output->writeln(sprintf('Hash: <info>%s</info>', $token->getHash()));
5663
$output->writeln(sprintf('Url: <info>%s</info>', $token->getTargetUrl()));
5764
$output->writeln(sprintf('Details: <info>%s</info>', (string) $token->getDetails() ?: 'null'));
5865

5966
return 0;
6067
}
61-
62-
/**
63-
* @return Payum
64-
*/
65-
protected function getPayum()
66-
{
67-
return $this->container->get('payum');
68-
}
6968
}

Command/DebugGatewayCommand.php

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@
33

44
use Payum\Core\Extension\StorageExtension;
55
use Payum\Core\Gateway;
6-
use Payum\Core\Registry\RegistryInterface;
6+
use Payum\Core\Payum;
77
use Payum\Core\Storage\AbstractStorage;
8+
use Symfony\Component\Console\Attribute\AsCommand;
89
use Symfony\Component\Console\Command\Command;
910
use Symfony\Component\Console\Input\InputArgument;
1011
use Symfony\Component\Console\Input\InputInterface;
1112
use Symfony\Component\Console\Input\InputOption;
1213
use Symfony\Component\Console\Output\OutputInterface;
1314
use Symfony\Component\Console\Question\ChoiceQuestion;
14-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
1615

17-
class DebugGatewayCommand extends Command implements ContainerAwareInterface
16+
#[AsCommand(name: 'debug:payum:gateway', aliases: ['payum:gateway:debug'])]
17+
class DebugGatewayCommand extends Command
1818
{
19-
use ContainerAwareTrait;
20-
2119
protected static $defaultName = 'debug:payum:gateway';
2220

21+
protected Payum $payum;
22+
23+
public function __construct(Payum $payum)
24+
{
25+
$this->payum = $payum;
26+
parent::__construct();
27+
}
28+
2329
/**
2430
* {@inheritDoc}
2531
*/
@@ -35,15 +41,16 @@ protected function configure(): void
3541

3642
/**
3743
* {@inheritDoc}
44+
* @throws \ReflectionException
3845
*/
3946
protected function execute(InputInterface $input, OutputInterface $output): int
4047
{
41-
$gateways = $this->getPayum()->getGateways();
48+
$gateways = $this->payum->getGateways();
4249

4350
if ($gatewayName = $input->getArgument('gateway-name')) {
4451
$gatewayName = $this->findProperGatewayName($input, $output, $gateways, $gatewayName);
4552
$gateways = array(
46-
$gatewayName => $this->getPayum()->getGateway($gatewayName),
53+
$gatewayName => $this->payum->getGateway($gatewayName),
4754
);
4855
}
4956

@@ -55,7 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5562
$output->writeln('');
5663
$output->writeln(sprintf('%s (%s):', $name, get_class($gateway)));
5764

58-
if (false == $gateway instanceof Gateway) {
65+
if (false === $gateway instanceof Gateway) {
5966
continue;
6067
}
6168

@@ -123,12 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
123130
return 0;
124131
}
125132

126-
/**
127-
* @param \ReflectionMethod $reflectionMethod
128-
*
129-
* @return array
130-
*/
131-
protected function getMethodCode(\ReflectionMethod $reflectionMethod)
133+
protected function getMethodCode(\ReflectionMethod $reflectionMethod): array
132134
{
133135
$file = file($reflectionMethod->getFileName());
134136

@@ -140,15 +142,7 @@ protected function getMethodCode(\ReflectionMethod $reflectionMethod)
140142
return array_values($methodCodeLines);
141143
}
142144

143-
/**
144-
* @return RegistryInterface
145-
*/
146-
protected function getPayum()
147-
{
148-
return $this->container->get('payum');
149-
}
150-
151-
private function findProperGatewayName(InputInterface $input, OutputInterface $output, $gateways, $name)
145+
private function findProperGatewayName(InputInterface $input, OutputInterface $output, array $gateways, string $name)
152146
{
153147
$helperSet = $this->getHelperSet();
154148
if (!$helperSet->has('question') || isset($gateways[$name]) || !$input->isInteractive()) {
@@ -165,14 +159,14 @@ private function findProperGatewayName(InputInterface $input, OutputInterface $o
165159
return $this->getHelper('question')->ask($input, $output, $question);
166160
}
167161

168-
private function findGatewaysContaining($gateways, $name)
162+
private function findGatewaysContaining(array $gateways, string $name): array
169163
{
170164
$threshold = 1e3;
171165
$foundGateways = array();
172166

173167
foreach ($gateways as $gatewayName => $gateway) {
174168
$lev = levenshtein($name, $gatewayName);
175-
if ($lev <= strlen($name) / 3 || false !== strpos($gatewayName, $name)) {
169+
if ($lev <= strlen($name) / 3 || str_contains($gatewayName, $name)) {
176170
$foundGateways[$gatewayName] = isset($foundGateways[$gatewayName]) ? $foundGateways[$gateway] - $lev : $lev;
177171
}
178172
}

0 commit comments

Comments
 (0)