From e26dd9a1f3fee9c2b34a18a1051d7dfd42ab645e Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 8 Apr 2024 18:36:41 +0200 Subject: [PATCH] Remove ContainerAwareInterface and ContainerAwareTrait --- Builder/CoreGatewayFactoryBuilder.php | 23 ++++++++----------- ContainerAwareCoreGatewayFactory.php | 14 +++++++---- ContainerAwareRegistry.php | 14 +++++++---- .../Compiler/BuildGatewayFactoriesPass.php | 2 +- .../ContainerAwareInterface.php | 11 --------- DependencyInjection/ContainerAwareTrait.php | 15 ------------ Resources/config/payum.xml | 9 ++------ .../Builder/CoreGatewayFactoryBuilderTest.php | 15 ++---------- .../ContainerAwareCoreGatewayFactoryTest.php | 23 ++++--------------- Tests/ContainerAwareRegistryTest.php | 17 +++----------- .../Command/CreateCaptureTokenCommandTest.php | 4 ---- .../Command/CreateNotifyTokenCommandTest.php | 4 ---- .../Command/DebugGatewayCommandTest.php | 5 ---- .../Functional/Command/StatusCommandTest.php | 4 ---- 14 files changed, 43 insertions(+), 117 deletions(-) delete mode 100644 DependencyInjection/ContainerAwareInterface.php delete mode 100644 DependencyInjection/ContainerAwareTrait.php diff --git a/Builder/CoreGatewayFactoryBuilder.php b/Builder/CoreGatewayFactoryBuilder.php index ce8d588..acd26c4 100644 --- a/Builder/CoreGatewayFactoryBuilder.php +++ b/Builder/CoreGatewayFactoryBuilder.php @@ -3,27 +3,24 @@ namespace Payum\Bundle\PayumBundle\Builder; use Payum\Bundle\PayumBundle\ContainerAwareCoreGatewayFactory; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareTrait; -use Payum\Core\GatewayFactoryInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; -class CoreGatewayFactoryBuilder implements ContainerAwareInterface +class CoreGatewayFactoryBuilder { - use ContainerAwareTrait; + private ContainerInterface $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } public function __invoke() { return call_user_func_array([$this, 'build'], func_get_args()); } - /** - * @return GatewayFactoryInterface - */ - public function build(array $defaultConfig) + public function build(array $defaultConfig): ContainerAwareCoreGatewayFactory { - $coreGatewayFactory = new ContainerAwareCoreGatewayFactory($defaultConfig); - $coreGatewayFactory->setContainer($this->container); - - return $coreGatewayFactory; + return new ContainerAwareCoreGatewayFactory($this->container, $defaultConfig); } } diff --git a/ContainerAwareCoreGatewayFactory.php b/ContainerAwareCoreGatewayFactory.php index 1e5f750..5bca8cb 100644 --- a/ContainerAwareCoreGatewayFactory.php +++ b/ContainerAwareCoreGatewayFactory.php @@ -2,14 +2,20 @@ namespace Payum\Bundle\PayumBundle; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareTrait; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\CoreGatewayFactory; +use Symfony\Component\DependencyInjection\ContainerInterface; -class ContainerAwareCoreGatewayFactory extends CoreGatewayFactory implements ContainerAwareInterface +class ContainerAwareCoreGatewayFactory extends CoreGatewayFactory { - use ContainerAwareTrait; + private ContainerInterface $container; + + public function __construct(ContainerInterface $container, array $defaultConfig = []) + { + $this->container = $container; + + parent::__construct($defaultConfig); + } protected function buildClosures(ArrayObject $config): void { diff --git a/ContainerAwareRegistry.php b/ContainerAwareRegistry.php index 755ca25..f9172ca 100644 --- a/ContainerAwareRegistry.php +++ b/ContainerAwareRegistry.php @@ -2,17 +2,23 @@ namespace Payum\Bundle\PayumBundle; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareTrait; use Payum\Core\Registry\AbstractRegistry; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * @template T of object * @extends AbstractRegistry */ -class ContainerAwareRegistry extends AbstractRegistry implements ContainerAwareInterface +class ContainerAwareRegistry extends AbstractRegistry { - use ContainerAwareTrait; + private ContainerInterface $container; + + public function __construct(array $gateways, array $storages, array $gatewayFactories, ContainerInterface $container) + { + parent::__construct($gateways, $storages, $gatewayFactories); + + $this->container = $container; + } protected function getService($id): ?object { diff --git a/DependencyInjection/Compiler/BuildGatewayFactoriesPass.php b/DependencyInjection/Compiler/BuildGatewayFactoriesPass.php index 5e8f8c2..57f4d59 100644 --- a/DependencyInjection/Compiler/BuildGatewayFactoriesPass.php +++ b/DependencyInjection/Compiler/BuildGatewayFactoriesPass.php @@ -28,4 +28,4 @@ public function process(ContainerBuilder $container): void $registry->replaceArgument(2, $servicesIds); } -} \ No newline at end of file +} diff --git a/DependencyInjection/ContainerAwareInterface.php b/DependencyInjection/ContainerAwareInterface.php deleted file mode 100644 index 7190f7e..0000000 --- a/DependencyInjection/ContainerAwareInterface.php +++ /dev/null @@ -1,11 +0,0 @@ -container = $container; - } - -} diff --git a/Resources/config/payum.xml b/Resources/config/payum.xml index 8b0fcda..86ef096 100644 --- a/Resources/config/payum.xml +++ b/Resources/config/payum.xml @@ -56,10 +56,7 @@ - - - - + @@ -93,9 +90,7 @@ - - - + diff --git a/Tests/Builder/CoreGatewayFactoryBuilderTest.php b/Tests/Builder/CoreGatewayFactoryBuilderTest.php index 74d970c..2fbe590 100644 --- a/Tests/Builder/CoreGatewayFactoryBuilderTest.php +++ b/Tests/Builder/CoreGatewayFactoryBuilderTest.php @@ -4,20 +4,11 @@ use Payum\Bundle\PayumBundle\Builder\CoreGatewayFactoryBuilder; use Payum\Bundle\PayumBundle\ContainerAwareCoreGatewayFactory; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface; use PHPUnit\Framework\TestCase; -use ReflectionClass; use Symfony\Component\DependencyInjection\Container; class CoreGatewayFactoryBuilderTest extends TestCase { - public function testShouldImplementContainerAwareInterface(): void - { - $rc = new ReflectionClass(CoreGatewayFactoryBuilder::class); - - $this->assertTrue($rc->implementsInterface(ContainerAwareInterface::class)); - } - public function testShouldBuildContainerAwareCoreGatewayFactory(): void { $container = new Container(); @@ -25,8 +16,7 @@ public function testShouldBuildContainerAwareCoreGatewayFactory(): void 'foo' => 'fooVal', ]; - $builder = new CoreGatewayFactoryBuilder(); - $builder->setContainer($container); + $builder = new CoreGatewayFactoryBuilder($container); $gatewayFactory = $builder->build($defaultConfig); @@ -40,8 +30,7 @@ public function testAllowUseBuilderAsAsFunction(): void 'foo' => 'fooVal', ]; - $builder = new CoreGatewayFactoryBuilder(); - $builder->setContainer($container); + $builder = new CoreGatewayFactoryBuilder($container); $gatewayFactory = $builder($defaultConfig); diff --git a/Tests/ContainerAwareCoreGatewayFactoryTest.php b/Tests/ContainerAwareCoreGatewayFactoryTest.php index ba22e9c..3aeecf7 100644 --- a/Tests/ContainerAwareCoreGatewayFactoryTest.php +++ b/Tests/ContainerAwareCoreGatewayFactoryTest.php @@ -10,7 +10,6 @@ use ReflectionClass; use stdClass; use Symfony\Component\DependencyInjection\Container; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface; class ContainerAwareCoreGatewayFactoryTest extends TestCase { @@ -21,21 +20,13 @@ public function testShouldExtendCoreGatewayFactory(): void $this->assertTrue($rc->isSubclassOf(CoreGatewayFactory::class)); } - public function testShouldImplementContainerAwareInterface(): void - { - $rc = new ReflectionClass(ContainerAwareCoreGatewayFactory::class); - - $this->assertTrue($rc->implementsInterface(ContainerAwareInterface::class)); - } - public function testShouldResolveContainerParameter(): void { $container = new Container(); $container->setParameter('foo', 'fooVal'); $container->setParameter('bar.baz_ololo', 'barBazOloloVal'); - $factory = new ContainerAwareCoreGatewayFactory(); - $factory->setContainer($container); + $factory = new ContainerAwareCoreGatewayFactory($container); $called = false; @@ -58,8 +49,7 @@ public function testShouldResolveTemplateFromContainerParameter(): void $container = new Container(); $container->setParameter('a_template_parameter', '@aTemplate'); - $factory = new ContainerAwareCoreGatewayFactory(); - $factory->setContainer($container); + $factory = new ContainerAwareCoreGatewayFactory($container); $called = false; @@ -79,8 +69,7 @@ public function testShouldSkipContainerServiceIfSuchNotExist(): void { $container = new Container(); - $factory = new ContainerAwareCoreGatewayFactory(); - $factory->setContainer($container); + $factory = new ContainerAwareCoreGatewayFactory($container); $called = false; @@ -103,8 +92,7 @@ public function testShouldResolveContainerServiceIfSuchExist(): void $container = new Container(); $container->set('anActionService', $service); - $factory = new ContainerAwareCoreGatewayFactory(); - $factory->setContainer($container); + $factory = new ContainerAwareCoreGatewayFactory($container); $called = false; @@ -122,8 +110,7 @@ public function testShouldResolveContainerServiceIfSuchExist(): void public function testShouldSkipEmptyStringValue(): void { - $factory = new ContainerAwareCoreGatewayFactory(); - $factory->setContainer(new Container()); + $factory = new ContainerAwareCoreGatewayFactory(new Container()); $this->assertInstanceOf(GatewayInterface::class, $factory->create([ 'foo' => '', diff --git a/Tests/ContainerAwareRegistryTest.php b/Tests/ContainerAwareRegistryTest.php index 00eb2f2..bb6f147 100644 --- a/Tests/ContainerAwareRegistryTest.php +++ b/Tests/ContainerAwareRegistryTest.php @@ -11,7 +11,6 @@ use ReflectionClass; use stdClass; use Symfony\Component\DependencyInjection\Container; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface; class ContainerAwareRegistryTest extends TestCase { @@ -22,13 +21,6 @@ public function testShouldBeSubClassOfAbstractRegistry(): void $this->assertTrue($rc->isSubclassOf(AbstractRegistry::class)); } - public function testShouldImplementContainerAwareInterface(): void - { - $rc = new ReflectionClass(ContainerAwareRegistry::class); - - $this->assertTrue($rc->implementsInterface(ContainerAwareInterface::class)); - } - public function testShouldReturnGatewaySetToContainer(): void { $gateways = [ @@ -39,8 +31,7 @@ public function testShouldReturnGatewaySetToContainer(): void $container = new Container(); $container->set('fooGatewayServiceId', $this->createMock(GatewayInterface::class)); - $registry = new ContainerAwareRegistry($gateways, $storages); - $registry->setContainer($container); + $registry = new ContainerAwareRegistry($gateways, $storages, [], $container); $this->assertSame( $container->get('fooGatewayServiceId'), @@ -58,8 +49,7 @@ public function testShouldReturnStorageSetToContainer(): void $container = new Container(); $container->set('fooStorageServiceId', $this->createMock(StorageInterface::class)); - $registry = new ContainerAwareRegistry($gateways, $storages); - $registry->setContainer($container); + $registry = new ContainerAwareRegistry($gateways, $storages, [], $container); $this->assertSame($container->get('fooStorageServiceId'), $registry->getStorage(stdClass::class)); } @@ -71,8 +61,7 @@ public function testShouldReturnGatewayFactorySetToContainer(): void $registry = new ContainerAwareRegistry([], [], [ 'fooName' => GatewayFactoryInterface::class, - ]); - $registry->setContainer($container); + ], $container); $this->assertSame($container->get(GatewayFactoryInterface::class), $registry->getGatewayFactory('fooName')); } diff --git a/Tests/Functional/Command/CreateCaptureTokenCommandTest.php b/Tests/Functional/Command/CreateCaptureTokenCommandTest.php index 0c972a6..02f9088 100644 --- a/Tests/Functional/Command/CreateCaptureTokenCommandTest.php +++ b/Tests/Functional/Command/CreateCaptureTokenCommandTest.php @@ -2,7 +2,6 @@ namespace Payum\Bundle\PayumBundle\Tests\Functional\Command; use Payum\Bundle\PayumBundle\Command\CreateCaptureTokenCommand; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface; use Payum\Bundle\PayumBundle\Tests\Functional\WebTestCase; use Payum\Core\Registry\RegistryInterface; use Symfony\Bundle\FrameworkBundle\Console\Application; @@ -75,9 +74,6 @@ public function shouldCreateCaptureTokenWithRouteAsAfterUrl(): void protected function executeConsole(Command $command, array $arguments = array()): string { $command->setApplication(new Application($this->client->getKernel())); - if ($command instanceof ContainerAwareInterface) { - $command->setContainer($this->client->getContainer()); - } $arguments = array_replace(array( '--env' => 'test', diff --git a/Tests/Functional/Command/CreateNotifyTokenCommandTest.php b/Tests/Functional/Command/CreateNotifyTokenCommandTest.php index 134e5b7..d77ef7e 100644 --- a/Tests/Functional/Command/CreateNotifyTokenCommandTest.php +++ b/Tests/Functional/Command/CreateNotifyTokenCommandTest.php @@ -2,7 +2,6 @@ namespace Payum\Bundle\PayumBundle\Tests\Functional\Command; use Payum\Bundle\PayumBundle\Command\CreateNotifyTokenCommand; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface; use Payum\Bundle\PayumBundle\Tests\Functional\WebTestCase; use Payum\Core\Registry\RegistryInterface; use Symfony\Bundle\FrameworkBundle\Console\Application; @@ -61,9 +60,6 @@ public function shouldCreateNotifyTokenWithModel(): void protected function executeConsole(Command $command, array $arguments = array()): string { $command->setApplication(new Application($this->client->getKernel())); - if ($command instanceof ContainerAwareInterface) { - $command->setContainer($this->client->getContainer()); - } $arguments = array_replace(array( '--env' => 'test', diff --git a/Tests/Functional/Command/DebugGatewayCommandTest.php b/Tests/Functional/Command/DebugGatewayCommandTest.php index 75bbcbc..79bd34b 100644 --- a/Tests/Functional/Command/DebugGatewayCommandTest.php +++ b/Tests/Functional/Command/DebugGatewayCommandTest.php @@ -2,7 +2,6 @@ namespace Payum\Bundle\PayumBundle\Tests\Functional\Command; use Payum\Bundle\PayumBundle\Command\DebugGatewayCommand; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface; use Payum\Bundle\PayumBundle\Tests\Functional\WebTestCase; use Payum\Core\Registry\RegistryInterface; use Symfony\Bundle\FrameworkBundle\Console\Application; @@ -96,10 +95,6 @@ protected function executeConsole(Command $command, array $arguments = [], array $command->setApplication(new Application($this->client->getKernel())); } - if ($command instanceof ContainerAwareInterface) { - $command->setContainer($this->client->getContainer()); - } - $arguments = array_replace(array( '--env' => 'test', 'command' => $command->getName(), diff --git a/Tests/Functional/Command/StatusCommandTest.php b/Tests/Functional/Command/StatusCommandTest.php index a6ddf9f..294f093 100644 --- a/Tests/Functional/Command/StatusCommandTest.php +++ b/Tests/Functional/Command/StatusCommandTest.php @@ -2,7 +2,6 @@ namespace Payum\Bundle\PayumBundle\Tests\Functional\Command; use Payum\Bundle\PayumBundle\Command\StatusCommand; -use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface; use Payum\Bundle\PayumBundle\Tests\Functional\WebTestCase; use Payum\Core\Registry\RegistryInterface; use Symfony\Bundle\FrameworkBundle\Console\Application; @@ -39,9 +38,6 @@ public function shouldReturnNewStatus(): void protected function executeConsole(Command $command, array $arguments = array()): string { $command->setApplication(new Application($this->client->getKernel())); - if ($command instanceof ContainerAwareInterface) { - $command->setContainer($this->client->getContainer()); - } $arguments = array_replace(array( '--env' => 'test',