Skip to content

Commit

Permalink
Sylius 1.11 compatibility layer
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Apr 15, 2022
1 parent 58fb92d commit e340aca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/DependencyInjection/Compiler/CreateServiceAliasesPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusGiftCardPlugin\DependencyInjection\Compiler;

use Sylius\Bundle\ApiBundle\Context\UserContextInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class CreateServiceAliasesPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
// if this service is already defined, we don't need to do anything. It means the Sylius version is < 1.11
if ($container->has('sylius.api.context.user')) {
return;
}

// this should not be possible after the check above, but we need to check it, obviously. This service was added in 1.11
if (!$container->has(UserContextInterface::class)) {
return;
}

$container->setAlias('sylius.api.context.user', UserContextInterface::class);
}
}
2 changes: 2 additions & 0 deletions src/SetonoSyliusGiftCardPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Setono\SyliusGiftCardPlugin;

use Setono\SyliusGiftCardPlugin\DependencyInjection\Compiler\AddAdjustmentsToOrderAdjustmentClearerPass;
use Setono\SyliusGiftCardPlugin\DependencyInjection\Compiler\CreateServiceAliasesPass;
use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait;
use Sylius\Bundle\ResourceBundle\AbstractResourceBundle;
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
Expand All @@ -19,6 +20,7 @@ public function build(ContainerBuilder $container): void
parent::build($container);

$container->addCompilerPass(new AddAdjustmentsToOrderAdjustmentClearerPass());
$container->addCompilerPass(new CreateServiceAliasesPass());
}

public function getSupportedDrivers(): array
Expand Down

0 comments on commit e340aca

Please sign in to comment.