Skip to content

Commit

Permalink
Minor improvements in replace email managers compiler passes
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Feb 2, 2024
1 parent a62a57e commit 3038c3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Sylius\Bundle\AdminBundle\EventListener\ShipmentShipListener;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\Reference;

/** @internal */
Expand All @@ -33,9 +32,9 @@ public function process(ContainerBuilder $container): void
continue;
}

$decoratedServiceClass = $definition->getDecoratedService()[0];
$decoratedServiceId = $definition->getDecoratedService()[0];

if ($decoratedServiceClass === OrderEmailManagerInterface::class) {
if ($decoratedServiceId === OrderEmailManagerInterface::class) {
$this->replaceArgument(
$container,
ResendOrderConfirmationEmailAction::class,
Expand All @@ -47,7 +46,7 @@ public function process(ContainerBuilder $container): void
continue;
}

if ($decoratedServiceClass === 'sylius.email_manager.shipment') {
if ($decoratedServiceId === 'sylius.email_manager.shipment') {
$this->replaceArgument(
$container,
'sylius.listener.shipment_ship',
Expand All @@ -59,7 +58,7 @@ public function process(ContainerBuilder $container): void
continue;
}

if ($decoratedServiceClass === ShipmentEmailManagerInterface::class) {
if ($decoratedServiceId === ShipmentEmailManagerInterface::class) {
$this->replaceArgument(
$container,
ResendShipmentConfirmationEmailAction::class,
Expand All @@ -78,13 +77,13 @@ public function replaceArgument(
int $argumentIndex,
string $argumentId,
): void {
try {
$listenerDefinition = $container->findDefinition($serviceId);
if ($listenerDefinition->getClass() === $serviceClass) {
$listenerDefinition->setArgument($argumentIndex, new Reference($argumentId));
}
} catch (ServiceNotFoundException) {
if (!$container->hasDefinition($serviceId)) {
return;
}

$definition = $container->findDefinition($serviceId);
if ($definition->getClass() === $serviceClass) {
$definition->setArgument($argumentIndex, new Reference($argumentId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Sylius\Bundle\ShopBundle\EventListener\OrderCompleteListener;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\Reference;

/** @internal */
Expand All @@ -30,9 +29,9 @@ public function process(ContainerBuilder $container): void
continue;
}

$decoratedServiceClass = $definition->getDecoratedService()[0];
$decoratedServiceId = $definition->getDecoratedService()[0];

if ($decoratedServiceClass === 'sylius.email_manager.contact') {
if ($decoratedServiceId === 'sylius.email_manager.contact') {
$this->replaceArgument(
$container,
'sylius.controller.shop.contact',
Expand All @@ -44,7 +43,7 @@ public function process(ContainerBuilder $container): void
continue;
}

if ($decoratedServiceClass === 'sylius.email_manager.order') {
if ($decoratedServiceId === 'sylius.email_manager.order') {
$this->replaceArgument(
$container,
'sylius.listener.order_complete',
Expand All @@ -63,13 +62,13 @@ public function replaceArgument(
int $argumentIndex,
string $argumentId,
): void {
try {
$listenerDefinition = $container->findDefinition($serviceId);
if ($listenerDefinition->getClass() === $serviceClass) {
$listenerDefinition->setArgument($argumentIndex, new Reference($argumentId));
}
} catch (ServiceNotFoundException) {
if (!$container->hasDefinition($serviceId)) {
return;
}

$definition = $container->findDefinition($serviceId);
if ($definition->getClass() === $serviceClass) {
$definition->setArgument($argumentIndex, new Reference($argumentId));
}
}
}

0 comments on commit 3038c3e

Please sign in to comment.