Skip to content

Commit

Permalink
Merge pull request #541 from Chris53897/feature/support-symfony6
Browse files Browse the repository at this point in the history
Feat: support symfony6
  • Loading branch information
pierredup committed Jul 4, 2022
2 parents 14604f9 + 82b09f2 commit 4322a97
Show file tree
Hide file tree
Showing 84 changed files with 588 additions and 445 deletions.
60 changes: 23 additions & 37 deletions .github/workflows/tests.yaml
Expand Up @@ -7,16 +7,31 @@ env:

jobs:
unit-test:
name: Unit ( PHP ${{ matrix.php }} )
name: Unit ( PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }} )
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- php: 7.4
symfony: 4.4.*
- php: 7.4
symfony: 5.4.*
- php: 8.0
symfony: 4.4.*
- php: 8.0
symfony: 5.4.*
- php: 8.0
symfony: 6.0.*
- php: 8.1
symfony: 4.4.*
- php: 8.1
symfony: 5.4.*
- php: 8.1
symfony: 6.0.*
- php: 8.1
symfony: 6.1.*

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

- name: Install dependencies
run: composer update

- name: Run unit tests
run: bin/phpunit

lowest:
name: Unit ( PHP ${{ matrix.php }} + Lowest )
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- php: 7.4

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: intl, opcache, mysql, pdo_mysql, :xdebug

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Install Symfony ${{ matrix.symfony }}
run: composer config extra.symfony.require ${{ matrix.symfony }}

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json composer.lock') }}
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer-
- name: Install Symfony Flex
run: |
composer require symfony/flex:^1 --no-update
composer config --no-plugins allow-plugins.symfony/flex true
- name: Install dependencies
run: composer update --prefer-lowest --prefer-stable
run: composer update

- name: Run unit tests
run: bin/phpunit
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

## 2.5.0 (2022-07-xx)

* Support for Symfony 5.0 - 5.3 dropped
* Added support for Symfony 6.0
* Minimum Payum Core dependency updated to 1.7.2

## 2.3.1 (2018-08-19)

* Make profiler dynamic
Expand Down
29 changes: 14 additions & 15 deletions Command/CreateCaptureTokenCommand.php
Expand Up @@ -3,20 +3,27 @@

use Payum\Core\Exception\RuntimeException;
use Payum\Core\Payum;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class CreateCaptureTokenCommand extends Command implements ContainerAwareInterface
#[AsCommand(name: 'payum:security:create-capture-token')]
class CreateCaptureTokenCommand extends Command
{
use ContainerAwareTrait;

protected static $defaultName = 'payum:security:create-capture-token';

private Payum $payum;

public function __construct(Payum $payum)
{
$this->payum = $payum;

parent::__construct();
}

/**
* {@inheritDoc}
*/
Expand All @@ -43,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

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

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

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

return 0;
}

/**
* @return Payum
*/
protected function getPayum()
{
return $this->container->get('payum');
}
}
29 changes: 14 additions & 15 deletions Command/CreateNotifyTokenCommand.php
Expand Up @@ -3,20 +3,27 @@

use Payum\Core\Exception\RuntimeException;
use Payum\Core\Payum;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class CreateNotifyTokenCommand extends Command implements ContainerAwareInterface
#[AsCommand(name: 'payum:security:create-notify-token')]
class CreateNotifyTokenCommand extends Command
{
use ContainerAwareTrait;

protected static $defaultName = 'payum:security:create-notify-token';

private Payum $payum;

public function __construct(Payum $payum)
{
$this->payum = $payum;

parent::__construct();
}

/**
* {@inheritDoc}
*/
Expand All @@ -41,7 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$model = null;

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

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

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

return 0;
}

/**
* @return Payum
*/
protected function getPayum()
{
return $this->container->get('payum');
}
}
46 changes: 20 additions & 26 deletions Command/DebugGatewayCommand.php
Expand Up @@ -3,23 +3,29 @@

use Payum\Core\Extension\StorageExtension;
use Payum\Core\Gateway;
use Payum\Core\Registry\RegistryInterface;
use Payum\Core\Payum;
use Payum\Core\Storage\AbstractStorage;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class DebugGatewayCommand extends Command implements ContainerAwareInterface
#[AsCommand(name: 'debug:payum:gateway', aliases: ['payum:gateway:debug'])]
class DebugGatewayCommand extends Command
{
use ContainerAwareTrait;

protected static $defaultName = 'debug:payum:gateway';

protected Payum $payum;

public function __construct(Payum $payum)
{
$this->payum = $payum;
parent::__construct();
}

/**
* {@inheritDoc}
*/
Expand All @@ -35,15 +41,16 @@ protected function configure(): void

/**
* {@inheritDoc}
* @throws \ReflectionException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$gateways = $this->getPayum()->getGateways();
$gateways = $this->payum->getGateways();

if ($gatewayName = $input->getArgument('gateway-name')) {
$gatewayName = $this->findProperGatewayName($input, $output, $gateways, $gatewayName);
$gateways = array(
$gatewayName => $this->getPayum()->getGateway($gatewayName),
$gatewayName => $this->payum->getGateway($gatewayName),
);
}

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

if (false == $gateway instanceof Gateway) {
if (false === $gateway instanceof Gateway) {
continue;
}

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

/**
* @param \ReflectionMethod $reflectionMethod
*
* @return array
*/
protected function getMethodCode(\ReflectionMethod $reflectionMethod)
protected function getMethodCode(\ReflectionMethod $reflectionMethod): array
{
$file = file($reflectionMethod->getFileName());

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

/**
* @return RegistryInterface
*/
protected function getPayum()
{
return $this->container->get('payum');
}

private function findProperGatewayName(InputInterface $input, OutputInterface $output, $gateways, $name)
private function findProperGatewayName(InputInterface $input, OutputInterface $output, array $gateways, string $name)
{
$helperSet = $this->getHelperSet();
if (!$helperSet->has('question') || isset($gateways[$name]) || !$input->isInteractive()) {
Expand All @@ -165,14 +159,14 @@ private function findProperGatewayName(InputInterface $input, OutputInterface $o
return $this->getHelper('question')->ask($input, $output, $question);
}

private function findGatewaysContaining($gateways, $name)
private function findGatewaysContaining(array $gateways, string $name): array
{
$threshold = 1e3;
$foundGateways = array();

foreach ($gateways as $gatewayName => $gateway) {
$lev = levenshtein($name, $gatewayName);
if ($lev <= strlen($name) / 3 || false !== strpos($gatewayName, $name)) {
if ($lev <= strlen($name) / 3 || str_contains($gatewayName, $name)) {
$foundGateways[$gatewayName] = isset($foundGateways[$gatewayName]) ? $foundGateways[$gateway] - $lev : $lev;
}
}
Expand Down

0 comments on commit 4322a97

Please sign in to comment.