1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Psi\Bundle\ContentType\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
9
|
|
|
|
10
|
|
|
class PsiContentTypeExtension extends Extension |
11
|
|
|
{ |
12
|
|
|
private $storageLoaders = []; |
13
|
|
|
|
14
|
|
|
public function getConfiguration(array $config, ContainerBuilder $container) |
15
|
|
|
{ |
16
|
|
|
return new Configuration($this->storageLoaders); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
public function load(array $configs, ContainerBuilder $container) |
23
|
|
|
{ |
24
|
|
|
$config = $this->processConfiguration($this->getConfiguration([], $container), $configs); |
|
|
|
|
25
|
|
|
|
26
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
27
|
|
|
$loader->load('metadata.xml'); |
28
|
|
|
$loader->load('form.xml'); |
29
|
|
|
$loader->load('services.xml'); |
30
|
|
|
$loader->load('fields.xml'); |
31
|
|
|
$loader->load('storage-types.xml'); |
32
|
|
|
$loader->load('views.xml'); |
33
|
|
|
$loader->load('console.xml'); |
34
|
|
|
|
35
|
|
|
$storages = $config['enabled_storage']; |
36
|
|
|
|
37
|
|
View Code Duplication |
if (!$storages) { |
|
|
|
|
38
|
|
|
throw new \InvalidArgumentException(sprintf( |
39
|
|
|
'No storage drivers specified for content-type component. Specify at least one of: "%s"', |
40
|
|
|
implode('", "', array_keys($this->storageLoaders)) |
41
|
|
|
)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
foreach ($storages as $storageName) { |
45
|
|
View Code Duplication |
if (!isset($this->storageLoaders[$storageName])) { |
|
|
|
|
46
|
|
|
throw new \InvalidArgumentException(sprintf( |
47
|
|
|
'Unknown storage "%s", known storages: "%s"', |
48
|
|
|
$storageName, |
49
|
|
|
implode('", "', array_keys($this->storageLoaders)) |
50
|
|
|
)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->storageLoaders[$storageName]->load($config['storage'][$storageName]); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function addStorageLoader($name, LoaderInterface $loader) |
58
|
|
|
{ |
59
|
|
|
$this->storageLoaders[$name] = $loader; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getAlias() |
63
|
|
|
{ |
64
|
|
|
return 'psi_content_type'; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: