Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sylius 1.11 compatibility layer #204

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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