Skip to content

Commit 73db718

Browse files
committed
Copy logic from SyliusPluginTrait to try and add Symfony Flex recipe
1 parent aa8caf9 commit 73db718

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

composer-require-checker.json

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"true",
1717
"void",
1818
"Sylius\\Bundle\\ChannelBundle\\Form\\Type\\ChannelChoiceType",
19-
"Sylius\\Bundle\\CoreBundle\\Application\\SyliusPluginTrait",
2019
"Sylius\\Bundle\\UiBundle\\Menu\\Event\\MenuBuilderEvent",
2120
"Sylius\\Component\\Channel\\Context\\ChannelContextInterface",
2221
"Sylius\\Component\\Channel\\Model\\ChannelInterface",

src/SetonoSyliusAnalyticsPlugin.php

+46-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
use Setono\CompositeCompilerPass\CompositeCompilerPass;
88
use Setono\SyliusAnalyticsPlugin\DependencyInjection\Compiler\OverrideDefaultContainerProviderPass;
99
use Setono\SyliusAnalyticsPlugin\DependencyInjection\Compiler\OverrideDefaultPropertyProviderPass;
10-
use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait;
1110
use Sylius\Bundle\ResourceBundle\AbstractResourceBundle;
1211
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
12+
use Symfony\Component\DependencyInjection\Container;
1313
use Symfony\Component\DependencyInjection\ContainerBuilder;
14+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
1415

1516
final class SetonoSyliusAnalyticsPlugin extends AbstractResourceBundle
1617
{
17-
use SyliusPluginTrait;
18-
1918
public function getSupportedDrivers(): array
2019
{
2120
return [
@@ -40,4 +39,48 @@ public function build(ContainerBuilder $container): void
4039
'setono_sylius_analytics.variant_resolver',
4140
));
4241
}
42+
43+
/**
44+
* Copied from @see \Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait to make the recipe work on symfony/recipes-contrib
45+
*
46+
* @psalm-suppress MixedInferredReturnType
47+
*/
48+
public function getContainerExtension(): ?ExtensionInterface
49+
{
50+
if (null === $this->extension) {
51+
$extension = $this->createContainerExtension();
52+
53+
if (null !== $extension) {
54+
if (!$extension instanceof ExtensionInterface) {
55+
throw new \LogicException(sprintf('Extension %s must implement %s.', get_class($extension), ExtensionInterface::class));
56+
}
57+
58+
// check naming convention for Sylius Plugins
59+
$basename = preg_replace('/Plugin$/', '', $this->getName());
60+
$expectedAlias = Container::underscore($basename);
61+
62+
if ($expectedAlias !== $extension->getAlias()) {
63+
throw new \LogicException(sprintf(
64+
'Users will expect the alias of the default extension of a plugin to be the underscored version of the plugin name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.',
65+
$expectedAlias,
66+
$extension->getAlias()
67+
));
68+
}
69+
70+
$this->extension = $extension;
71+
} else {
72+
$this->extension = false;
73+
}
74+
}
75+
76+
/** @psalm-suppress MixedReturnStatement */
77+
return $this->extension ?: null;
78+
}
79+
80+
protected function getContainerExtensionClass(): string
81+
{
82+
$basename = preg_replace('/Plugin$/', '', $this->getName());
83+
84+
return $this->getNamespace() . '\\DependencyInjection\\' . $basename . 'Extension';
85+
}
4386
}

0 commit comments

Comments
 (0)