|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of Goodwix Doctrine JSON ODM. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Goodwix\DoctrineJsonOdm\Bridge\Symfony\DependencyInjection; |
|
10
|
|
|
|
|
11
|
|
|
use Ramsey\Collection\CollectionInterface; |
|
12
|
|
|
use Ramsey\Collection\Map\TypedMapInterface; |
|
13
|
|
|
use Symfony\Component\Config\FileLocator; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
18
|
|
|
|
|
19
|
|
|
class DoctrineJsonOdmExtension extends Extension implements PrependExtensionInterface |
|
20
|
|
|
{ |
|
21
|
1 |
|
public function prepend(ContainerBuilder $container): void |
|
22
|
|
|
{ |
|
23
|
1 |
|
$frameworkConfiguration = $container->getExtensionConfig('framework'); |
|
24
|
|
|
|
|
25
|
1 |
|
if (empty($frameworkConfiguration)) { |
|
26
|
|
|
return; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
1 |
|
if (!isset($frameworkConfiguration['serializer']['enabled'])) { |
|
30
|
1 |
|
$container->prependExtensionConfig('framework', ['serializer' => ['enabled' => true]]); |
|
31
|
|
|
} |
|
32
|
1 |
|
} |
|
33
|
|
|
|
|
34
|
5 |
|
public function load(array $configs, ContainerBuilder $container): void |
|
35
|
|
|
{ |
|
36
|
5 |
|
$this->loadServices($container); |
|
37
|
5 |
|
$this->prepareConfiguration($configs, $container); |
|
38
|
2 |
|
} |
|
39
|
|
|
|
|
40
|
5 |
|
private function loadServices(ContainerBuilder $container): void |
|
41
|
|
|
{ |
|
42
|
5 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
43
|
5 |
|
$loader->load('services.xml'); |
|
44
|
|
|
|
|
45
|
|
|
if ( |
|
46
|
5 |
|
interface_exists(CollectionInterface::class) |
|
47
|
5 |
|
&& interface_exists(TypedMapInterface::class) |
|
48
|
|
|
) { |
|
49
|
5 |
|
$loader->load('ramsey_collection_normalizers.xml'); |
|
50
|
|
|
} |
|
51
|
5 |
|
} |
|
52
|
|
|
|
|
53
|
5 |
|
private function prepareConfiguration(array $configs, ContainerBuilder $container): void |
|
54
|
|
|
{ |
|
55
|
5 |
|
$configuration = new Configuration(); |
|
56
|
5 |
|
$processedConfiguration = $this->processConfiguration($configuration, $configs); |
|
57
|
|
|
|
|
58
|
2 |
|
$container->setParameter(ODMTypeCompilerPass::ODM_PATHS, $processedConfiguration['mapping']['paths']); |
|
59
|
2 |
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|