7
7
use Setono \CompositeCompilerPass \CompositeCompilerPass ;
8
8
use Setono \SyliusAnalyticsPlugin \DependencyInjection \Compiler \OverrideDefaultContainerProviderPass ;
9
9
use Setono \SyliusAnalyticsPlugin \DependencyInjection \Compiler \OverrideDefaultPropertyProviderPass ;
10
- use Sylius \Bundle \CoreBundle \Application \SyliusPluginTrait ;
11
10
use Sylius \Bundle \ResourceBundle \AbstractResourceBundle ;
12
11
use Sylius \Bundle \ResourceBundle \SyliusResourceBundle ;
12
+ use Symfony \Component \DependencyInjection \Container ;
13
13
use Symfony \Component \DependencyInjection \ContainerBuilder ;
14
+ use Symfony \Component \DependencyInjection \Extension \ExtensionInterface ;
14
15
15
16
final class SetonoSyliusAnalyticsPlugin extends AbstractResourceBundle
16
17
{
17
- use SyliusPluginTrait;
18
-
19
18
public function getSupportedDrivers (): array
20
19
{
21
20
return [
@@ -40,4 +39,48 @@ public function build(ContainerBuilder $container): void
40
39
'setono_sylius_analytics.variant_resolver ' ,
41
40
));
42
41
}
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
+ }
43
86
}
0 commit comments