Skip to content

Commit

Permalink
Copy logic from SyliusPluginTrait to try and add Symfony Flex recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jul 12, 2023
1 parent aa8caf9 commit 73db718
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
1 change: 0 additions & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"true",
"void",
"Sylius\\Bundle\\ChannelBundle\\Form\\Type\\ChannelChoiceType",
"Sylius\\Bundle\\CoreBundle\\Application\\SyliusPluginTrait",
"Sylius\\Bundle\\UiBundle\\Menu\\Event\\MenuBuilderEvent",
"Sylius\\Component\\Channel\\Context\\ChannelContextInterface",
"Sylius\\Component\\Channel\\Model\\ChannelInterface",
Expand Down
49 changes: 46 additions & 3 deletions src/SetonoSyliusAnalyticsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
use Setono\CompositeCompilerPass\CompositeCompilerPass;
use Setono\SyliusAnalyticsPlugin\DependencyInjection\Compiler\OverrideDefaultContainerProviderPass;
use Setono\SyliusAnalyticsPlugin\DependencyInjection\Compiler\OverrideDefaultPropertyProviderPass;
use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait;
use Sylius\Bundle\ResourceBundle\AbstractResourceBundle;
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;

final class SetonoSyliusAnalyticsPlugin extends AbstractResourceBundle
{
use SyliusPluginTrait;

public function getSupportedDrivers(): array
{
return [
Expand All @@ -40,4 +39,48 @@ public function build(ContainerBuilder $container): void
'setono_sylius_analytics.variant_resolver',
));
}

/**
* Copied from @see \Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait to make the recipe work on symfony/recipes-contrib
*
* @psalm-suppress MixedInferredReturnType
*/
public function getContainerExtension(): ?ExtensionInterface
{
if (null === $this->extension) {
$extension = $this->createContainerExtension();

if (null !== $extension) {
if (!$extension instanceof ExtensionInterface) {
throw new \LogicException(sprintf('Extension %s must implement %s.', get_class($extension), ExtensionInterface::class));
}

// check naming convention for Sylius Plugins
$basename = preg_replace('/Plugin$/', '', $this->getName());
$expectedAlias = Container::underscore($basename);

if ($expectedAlias !== $extension->getAlias()) {
throw new \LogicException(sprintf(
'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.',
$expectedAlias,
$extension->getAlias()
));
}

$this->extension = $extension;
} else {
$this->extension = false;
}
}

/** @psalm-suppress MixedReturnStatement */
return $this->extension ?: null;
}

protected function getContainerExtensionClass(): string
{
$basename = preg_replace('/Plugin$/', '', $this->getName());

return $this->getNamespace() . '\\DependencyInjection\\' . $basename . 'Extension';
}
}

0 comments on commit 73db718

Please sign in to comment.