|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Alpixel\Bundle\CMSBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
9
|
|
|
use Symfony\Component\Form\Exception\InvalidConfigurationException; |
|
10
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
11
|
|
|
use Symfony\Component\Yaml\Parser; |
|
12
|
|
|
|
|
13
|
|
|
class AlpixelCMSExtension extends Extension implements PrependExtensionInterface |
|
14
|
|
|
{ |
|
15
|
|
|
private $_blockDefaultClass = 'Alpixel\Bundle\CMSBundle\Entity\Block'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritdoc} |
|
19
|
|
|
*/ |
|
20
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
21
|
|
|
{ |
|
22
|
|
|
$configuration = new Configuration(); |
|
23
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
24
|
|
|
|
|
25
|
|
|
foreach ($config['content_types'] as $name => $contentType) { |
|
26
|
|
|
if (empty($contentType['title'])) { |
|
27
|
|
|
throw new InvalidConfigurationException('Content type '.$name.' shoud have a title'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
if (empty($contentType['description'])) { |
|
31
|
|
|
@trigger_error('Content type '.$name.' shoud have a description', E_USER_WARNING); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (!isset($contentType['class']) || empty($contentType['class']) || !class_exists($contentType['class'])) { |
|
35
|
|
|
throw new InvalidConfigurationException('CMS '.$contentType['class'].' can\'t be found'); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
$container->setParameter('alpixel_cms.content_types', $config['content_types']); |
|
39
|
|
|
|
|
40
|
|
|
foreach ($config['blocks'] as $name => $contentType) { |
|
41
|
|
|
if (empty($contentType['title'])) { |
|
42
|
|
|
throw new InvalidConfigurationException('Block '.$name.' shoud have a title'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if ((!isset($contentType['class']) || empty($contentType['class'])) && class_exists($this->_blockDefaultClass)) { |
|
46
|
|
|
$config['blocks'][$name]['class'] = $this->_blockDefaultClass; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (isset($contentType['class']) && !class_exists($contentType['class'])) { |
|
50
|
|
|
throw new InvalidConfigurationException('Block '.$contentType['class'].' can\'t be found'); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
$container->setParameter('alpixel_cms.blocks', $config['blocks']); |
|
54
|
|
|
$container->setParameter('alpixel_cms.exception_template', $config['exception_template']); |
|
55
|
|
|
|
|
56
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
57
|
|
|
$loader->load('services.yml'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function prepend(ContainerBuilder $container) |
|
61
|
|
|
{ |
|
62
|
|
|
$parser = new Parser(); |
|
63
|
|
|
|
|
64
|
|
|
$configs = $container->getExtensionConfig($this->getAlias()); |
|
65
|
|
|
$bundleConfig = $this->processConfiguration(new Configuration(), $configs); |
|
66
|
|
|
|
|
67
|
|
|
$config = $parser->parse(file_get_contents(__DIR__.'/../Resources/config/config.yml')); |
|
68
|
|
|
|
|
69
|
|
|
foreach ($config as $key => $configuration) { |
|
|
|
|
|
|
70
|
|
|
if ($key == 'sonata_admin' && $bundleConfig['white_label'] === true) { |
|
71
|
|
|
foreach ($configuration['dashboard']['blocks'] as $blockKey => $block) { |
|
72
|
|
|
if ($block['type'] === 'alpixel_cms.sonata.admin.block.alpixel') { |
|
73
|
|
|
unset($configuration['dashboard']['blocks'][$blockKey]); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
$container->prependExtensionConfig($key, $configuration); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.