1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Obblm\Core\Routing\AutoloadedRouteInterface; |
6
|
|
|
use Obblm\Core\Contracts\RuleHelperInterface; |
7
|
|
|
use Symfony\Component\Config\FileLocator; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
10
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
11
|
|
|
|
12
|
|
|
class ObblmCoreExtension extends Extension |
13
|
|
|
{ |
14
|
|
|
public function getAlias() |
15
|
|
|
{ |
16
|
|
|
return 'obblm'; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function getContainerExtension() |
20
|
|
|
{ |
21
|
|
|
return $this->extension; |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function load(array $configs, ContainerBuilder $container) |
25
|
|
|
{ |
26
|
|
|
$configuration = new Configuration(); |
27
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
28
|
|
|
|
29
|
|
|
foreach ($configs as $subConfig) { |
30
|
|
|
if ($subConfig) { |
31
|
|
|
$config = array_merge($config, $subConfig); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$this->createAssetsDirectoriesConfiguration($container, $config); |
36
|
|
|
|
37
|
|
|
$locator = new FileLocator(dirname(__DIR__).'/Resources/config'); |
38
|
|
|
$loader = new YamlFileLoader($container, $locator); |
39
|
|
|
$loader->load('services.yaml'); |
40
|
|
|
|
41
|
|
|
$container->registerForAutoconfiguration(RuleHelperInterface::class) |
42
|
|
|
->addTag('obblm.rule_helpers') |
43
|
|
|
; |
44
|
|
|
$container->registerForAutoconfiguration(AutoloadedRouteInterface::class) |
45
|
|
|
->addTag('obblm.routes') |
46
|
|
|
; |
47
|
|
|
|
48
|
|
|
$this->createRulesPoolCacheDefinition($container, $config); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
private function createAssetsDirectoriesConfiguration(ContainerBuilder $container, $config) |
52
|
|
|
{ |
53
|
|
|
// Upload |
54
|
|
|
$uploadDirectory = (!isset($config['obblm.upload_directory'])) ? |
55
|
|
|
$uploadDirectory = $container->getParameter('kernel.project_dir') . '/public/obblm/uploads' : |
|
|
|
|
56
|
|
|
$config['obblm.upload_directory']; |
57
|
|
|
$container->setParameter('obblm.config.directory.upload', $uploadDirectory); |
58
|
|
|
|
59
|
|
|
// Image resize cache |
60
|
|
|
$uploadDirectory = (!isset($config['obblm.public_cache_directory'])) ? |
61
|
|
|
$uploadDirectory = $container->getParameter('kernel.project_dir') . '/public/obblm/cache' : |
62
|
|
|
$config['obblm.public_cache_directory']; |
63
|
|
|
$container->setParameter('obblm.config.directory.public.cache', $uploadDirectory); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function createRulesPoolCacheDefinition(ContainerBuilder $container, array $config) : string |
67
|
|
|
{ |
68
|
|
|
$serviceId = 'obblm.cache.rules'; |
69
|
|
|
$default = $container->getDefinition('obblm.cache'); |
70
|
|
|
$default->addTag('cache.pool'); |
71
|
|
|
$container->setDefinition('obblm.cache', $default); |
72
|
|
|
if ($config['caches']) { |
73
|
|
|
foreach ($config['caches'] as $part => $options) { |
74
|
|
|
if (isset($options['adapter'])) { |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
return $serviceId; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|