Skip to content

Commit

Permalink
Remove ContainerAwareInterface and ContainerAwareTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed Apr 11, 2024
1 parent f9b019e commit e26dd9a
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 117 deletions.
23 changes: 10 additions & 13 deletions Builder/CoreGatewayFactoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
14 changes: 10 additions & 4 deletions ContainerAwareCoreGatewayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
14 changes: 10 additions & 4 deletions ContainerAwareRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
*/
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
{
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/BuildGatewayFactoriesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public function process(ContainerBuilder $container): void

$registry->replaceArgument(2, $servicesIds);
}
}
}
11 changes: 0 additions & 11 deletions DependencyInjection/ContainerAwareInterface.php

This file was deleted.

15 changes: 0 additions & 15 deletions DependencyInjection/ContainerAwareTrait.php

This file was deleted.

9 changes: 2 additions & 7 deletions Resources/config/payum.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@
<argument type="collection" /> <!-- gateways services. this should be replaced while container is built -->
<argument type="collection" /> <!-- storages services. this should be replaced while container is built -->
<argument type="collection" /> <!-- gateways factories services. this should be replaced while container is built -->

<call method="setContainer">
<argument type="service" id="service_container" />
</call>
<argument type="service" id="service_container" />
</service>

<service id="payum.converter.reply_to_http_response" class="Payum\Bundle\PayumBundle\ReplyToSymfonyResponseConverter" />
Expand Down Expand Up @@ -93,9 +90,7 @@
<service id="payum.http_request_verifier_builder" class="Payum\Bundle\PayumBundle\Builder\HttpRequestVerifierBuilder" public="false" />

<service id="payum.core_gateway_factory_builder" class="Payum\Bundle\PayumBundle\Builder\CoreGatewayFactoryBuilder" public="false">
<call method="setContainer">
<argument type="service" id="service_container" />
</call>
<argument type="service" id="service_container" />
</service>

<service id="payum.action.obtain_credit_card_builder" class="Payum\Bundle\PayumBundle\Builder\ObtainCreditCardActionBuilder">
Expand Down
15 changes: 2 additions & 13 deletions Tests/Builder/CoreGatewayFactoryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,19 @@

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();
$defaultConfig = [
'foo' => 'fooVal',
];

$builder = new CoreGatewayFactoryBuilder();
$builder->setContainer($container);
$builder = new CoreGatewayFactoryBuilder($container);

$gatewayFactory = $builder->build($defaultConfig);

Expand All @@ -40,8 +30,7 @@ public function testAllowUseBuilderAsAsFunction(): void
'foo' => 'fooVal',
];

$builder = new CoreGatewayFactoryBuilder();
$builder->setContainer($container);
$builder = new CoreGatewayFactoryBuilder($container);

$gatewayFactory = $builder($defaultConfig);

Expand Down
23 changes: 5 additions & 18 deletions Tests/ContainerAwareCoreGatewayFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use ReflectionClass;
use stdClass;
use Symfony\Component\DependencyInjection\Container;
use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface;

class ContainerAwareCoreGatewayFactoryTest extends TestCase
{
Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -79,8 +69,7 @@ public function testShouldSkipContainerServiceIfSuchNotExist(): void
{
$container = new Container();

$factory = new ContainerAwareCoreGatewayFactory();
$factory->setContainer($container);
$factory = new ContainerAwareCoreGatewayFactory($container);

$called = false;

Expand All @@ -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;

Expand All @@ -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' => '',
Expand Down
17 changes: 3 additions & 14 deletions Tests/ContainerAwareRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use ReflectionClass;
use stdClass;
use Symfony\Component\DependencyInjection\Container;
use Payum\Bundle\PayumBundle\DependencyInjection\ContainerAwareInterface;

class ContainerAwareRegistryTest extends TestCase
{
Expand All @@ -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 = [
Expand All @@ -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'),
Expand All @@ -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));
}
Expand All @@ -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'));
}
Expand Down
4 changes: 0 additions & 4 deletions Tests/Functional/Command/CreateCaptureTokenCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 0 additions & 4 deletions Tests/Functional/Command/CreateNotifyTokenCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 0 additions & 5 deletions Tests/Functional/Command/DebugGatewayCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 0 additions & 4 deletions Tests/Functional/Command/StatusCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit e26dd9a

Please sign in to comment.