|
8 | 8 | use Symfony\Component\Config\FileLocator;
|
9 | 9 | use Symfony\Component\Config\Resource\FileResource;
|
10 | 10 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
| 11 | +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
11 | 12 | use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
12 | 13 | use Symfony\Component\DependencyInjection\Reference;
|
13 | 14 | use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
14 | 15 |
|
15 |
| -class EnqueueExtension extends Extension |
| 16 | +class EnqueueExtension extends Extension implements PrependExtensionInterface |
16 | 17 | {
|
17 | 18 | /**
|
18 | 19 | * @var TransportFactoryInterface[]
|
@@ -132,4 +133,43 @@ public function getConfiguration(array $config, ContainerBuilder $container)
|
132 | 133 |
|
133 | 134 | return new Configuration($this->factories);
|
134 | 135 | }
|
| 136 | + |
| 137 | + public function prepend(ContainerBuilder $container) |
| 138 | + { |
| 139 | + $this->registerJobQueueDoctrineEntityMapping($container); |
| 140 | + } |
| 141 | + |
| 142 | + private function registerJobQueueDoctrineEntityMapping(ContainerBuilder $container) |
| 143 | + { |
| 144 | + if (false == class_exists(Job::class)) { |
| 145 | + return; |
| 146 | + } |
| 147 | + |
| 148 | + $bundles = $container->getParameter('kernel.bundles'); |
| 149 | + |
| 150 | + if (false == isset($bundles['DoctrineBundle'])) { |
| 151 | + return; |
| 152 | + } |
| 153 | + |
| 154 | + foreach ($container->getExtensionConfig('doctrine') as $config) { |
| 155 | + // do not register mappings if dbal not configured. |
| 156 | + if (false == empty($config['dbal'])) { |
| 157 | + $rc = new \ReflectionClass(Job::class); |
| 158 | + $jobQueueRootDir = dirname($rc->getFileName()); |
| 159 | + $container->prependExtensionConfig('doctrine', [ |
| 160 | + 'orm' => [ |
| 161 | + 'mappings' => [ |
| 162 | + 'enqueue_job_queue' => [ |
| 163 | + 'is_bundle' => false, |
| 164 | + 'type' => 'xml', |
| 165 | + 'dir' => $jobQueueRootDir.'/Doctrine/mapping', |
| 166 | + 'prefix' => 'Enqueue\JobQueue\Doctrine\Entity', |
| 167 | + ], |
| 168 | + ], |
| 169 | + ], |
| 170 | + ]); |
| 171 | + break; |
| 172 | + } |
| 173 | + } |
| 174 | + } |
135 | 175 | }
|
0 commit comments