|
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\Loader; |
|
8
|
|
|
use Symfony\Component\Form\Exception\InvalidConfigurationException; |
|
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
10
|
|
|
|
|
11
|
|
|
class AlpixelCMSExtension extends Extension |
|
12
|
|
|
{ |
|
13
|
|
|
private $_blockDefaultClass = 'Alpixel\Bundle\CMSBundle\Entity\Block'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* {@inheritdoc} |
|
17
|
|
|
*/ |
|
18
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
19
|
|
|
{ |
|
20
|
|
|
$configuration = new Configuration(); |
|
21
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
22
|
|
|
|
|
23
|
|
|
foreach ($config['content_types'] as $name => $contentType) { |
|
24
|
|
|
if (empty($contentType['title'])) { |
|
25
|
|
|
throw new InvalidConfigurationException('Content type '.$name.' shoud have a title'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
if (empty($contentType['description'])) { |
|
29
|
|
|
throw new InvalidConfigurationException('Content type '.$name.' shoud have a description'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if (!isset($contentType['class']) || empty($contentType['class']) || !class_exists($contentType['class'])) { |
|
33
|
|
|
throw new InvalidConfigurationException('CMS '.$contentType['class'].' can\'t be found'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if (empty($contentType['controller'])) { |
|
37
|
|
|
throw new InvalidConfigurationException('CMS '.$contentType['controller'].' can\'t be found'); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
$container->setParameter('cms.content_types', $config['content_types']); |
|
41
|
|
|
|
|
42
|
|
|
foreach ($config['blocks'] as $name => $contentType) { |
|
43
|
|
|
if (empty($contentType['title'])) { |
|
44
|
|
|
throw new InvalidConfigurationException('Block '.$name.' shoud have a title'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if ((!isset($contentType['class']) || empty($contentType['class'])) && class_exists($this->_blockDefaultClass)) { |
|
48
|
|
|
$config['blocks'][$name]['class'] = $this->_blockDefaultClass; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (isset($contentType['class']) && !class_exists($contentType['class'])) { |
|
52
|
|
|
throw new InvalidConfigurationException('Block '.$contentType['class'].' can\'t be found'); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
$container->setParameter('cms.blocks', $config['blocks']); |
|
56
|
|
|
|
|
57
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
58
|
|
|
$loader->load('services.yml'); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|