|
9 | 9 | use Storybook\Command\StorybookInitCommand; |
10 | 10 | use Storybook\Controller\StorybookController; |
11 | 11 | use Storybook\DependencyInjection\Compiler\ComponentMockPass; |
12 | | -use Storybook\EventListener\ComponentMockSubscriber; |
13 | 12 | use Storybook\EventListener\ProxyRequestListener; |
14 | 13 | use Storybook\Exception\UnauthorizedStoryException; |
15 | 14 | use Storybook\Mock\ComponentProxyFactory; |
16 | 15 | use Storybook\StoryRenderer; |
| 16 | +use Storybook\Twig\StorybookEnvironment; |
17 | 17 | use Storybook\Twig\StorybookEnvironmentConfigurator; |
| 18 | +use Storybook\Twig\StoryExtension; |
18 | 19 | use Storybook\Twig\TwigComponentSubscriber; |
19 | 20 | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
20 | 21 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
21 | 22 | use Symfony\Component\Config\Definition\ConfigurationInterface; |
22 | 23 | use Symfony\Component\Config\Definition\Processor; |
23 | 24 | use Symfony\Component\DependencyInjection\Argument\AbstractArgument; |
| 25 | +use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; |
24 | 26 | use Symfony\Component\DependencyInjection\ChildDefinition; |
25 | 27 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
26 | 28 | use Symfony\Component\DependencyInjection\Extension\Extension; |
27 | 29 | use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
28 | 30 | use Symfony\Component\DependencyInjection\Reference; |
| 31 | +use Twig\Extension\SandboxExtension; |
29 | 32 | use Twig\Sandbox\SecurityPolicy; |
30 | 33 |
|
31 | 34 | /** |
@@ -97,14 +100,35 @@ static function (ChildDefinition $definition, AsComponentMock $attributeInstance |
97 | 100 | ->setArgument(4, $sandboxConfig['allowedFunctions']) |
98 | 101 | ; |
99 | 102 |
|
| 103 | + // Storybook Twig extensions |
| 104 | + $container->setDefinition('storybook.twig', new ChildDefinition('twig')) |
| 105 | + ->setClass(StorybookEnvironment::class) |
| 106 | + ->addMethodCall('setComponentRuntime', [new Reference('storybook.twig.component_runtime')]) |
| 107 | + ->setConfigurator([new Reference('storybook.twig.environment_configurator'), 'configure']) |
| 108 | + ; |
| 109 | + |
| 110 | + $container->register('storybook.twig.extension.sandbox', SandboxExtension::class) |
| 111 | + ->setArgument(0, new Reference('storybook.twig.security_policy')) |
| 112 | + ->addTag('storybook.twig.extension') |
| 113 | + ; |
| 114 | + |
| 115 | + $container->register('storybook.twig.extension.story', StoryExtension::class) |
| 116 | + ->setArgument(0, new Reference('storybook.component_proxy_factory')) |
| 117 | + ->addTag('storybook.twig.extension') |
| 118 | + ; |
| 119 | + |
100 | 120 | $container->register('storybook.twig.environment_configurator', StorybookEnvironmentConfigurator::class) |
101 | 121 | ->setArgument(0, new Reference('twig.configurator.environment')) |
102 | | - ->setArgument(1, new Reference('storybook.twig.security_policy')) |
| 122 | + ->setArgument(1, new TaggedIteratorArgument('storybook.twig.extension')) |
103 | 123 | ->setArgument(2, $config['cache'] ?? false) |
104 | 124 | ; |
105 | 125 |
|
106 | | - $container->setDefinition('storybook.twig', new ChildDefinition('twig')) |
107 | | - ->setConfigurator([new Reference('storybook.twig.environment_configurator'), 'configure']) |
| 126 | + $container->setDefinition('storybook.twig.component_runtime', new ChildDefinition('.ux.twig_component.twig.component_runtime')) |
| 127 | + ->replaceArgument(0, new Reference('storybook.twig.component_renderer')) |
| 128 | + ; |
| 129 | + |
| 130 | + $container->setDefinition('storybook.twig.component_renderer', new ChildDefinition('ux.twig_component.component_renderer')) |
| 131 | + ->replaceArgument(0, new Reference('storybook.twig')) |
108 | 132 | ; |
109 | 133 |
|
110 | 134 | $container->register('storybook.story_renderer', StoryRenderer::class) |
@@ -135,10 +159,6 @@ static function (ChildDefinition $definition, AsComponentMock $attributeInstance |
135 | 159 | ->setArgument(0, new Reference('request_stack')) |
136 | 160 | ->setArgument(1, new Reference('event_dispatcher')) |
137 | 161 | ->addTag('kernel.event_subscriber'); |
138 | | - |
139 | | - $container->register('storybook.component_mock_subscriber', ComponentMockSubscriber::class) |
140 | | - ->setArgument(0, new Reference('storybook.component_proxy_factory')) |
141 | | - ->addTag('kernel.event_subscriber'); |
142 | 162 | } |
143 | 163 |
|
144 | 164 | public function getConfigTreeBuilder(): TreeBuilder |
|
0 commit comments