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
|
2 |
|
public function getAlias() |
15
|
|
|
{ |
16
|
2 |
|
return 'obblm'; |
17
|
|
|
} |
18
|
|
|
|
19
|
2 |
|
public function load(array $configs, ContainerBuilder $container) |
20
|
|
|
{ |
21
|
2 |
|
$configuration = new Configuration(); |
22
|
2 |
|
$config = $this->processConfiguration($configuration, $configs); |
23
|
|
|
|
24
|
2 |
|
foreach ($configs as $subConfig) { |
25
|
2 |
|
if ($subConfig) { |
26
|
|
|
$config = array_merge($config, $subConfig); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
2 |
|
$this->createAssetsDirectoriesConfiguration($container, $config); |
31
|
|
|
|
32
|
2 |
|
$locator = new FileLocator(dirname(__DIR__) . '/Resources/config'); |
33
|
2 |
|
$loader = new YamlFileLoader($container, $locator); |
34
|
2 |
|
$loader->load('services.yaml'); |
35
|
|
|
|
36
|
2 |
|
$container->registerForAutoconfiguration(RuleHelperInterface::class) |
37
|
2 |
|
->addTag('obblm.rule_helpers') |
38
|
|
|
; |
39
|
2 |
|
$container->registerForAutoconfiguration(AutoloadedRouteInterface::class) |
40
|
2 |
|
->addTag('obblm.routes') |
41
|
|
|
; |
42
|
|
|
|
43
|
2 |
|
$this->createRulesPoolCacheDefinition($container, $config); |
44
|
2 |
|
} |
45
|
|
|
|
46
|
2 |
|
private function createAssetsDirectoriesConfiguration(ContainerBuilder $container, $config) |
47
|
|
|
{ |
48
|
|
|
// Upload |
49
|
2 |
|
$uploadDirectory = (!isset($config['obblm.upload_directory'])) ? |
50
|
2 |
|
$uploadDirectory = $container->getParameter('kernel.project_dir') . '/public/obblm/uploads' : |
|
|
|
|
51
|
2 |
|
$config['obblm.upload_directory']; |
52
|
2 |
|
$container->setParameter('obblm.config.directory.upload', $uploadDirectory); |
53
|
|
|
|
54
|
|
|
// Image resize cache |
55
|
2 |
|
$uploadDirectory = (!isset($config['obblm.public_cache_directory'])) ? |
56
|
2 |
|
$uploadDirectory = $container->getParameter('kernel.project_dir') . '/public/obblm/cache' : |
57
|
2 |
|
$config['obblm.public_cache_directory']; |
58
|
2 |
|
$container->setParameter('obblm.config.directory.public.cache', $uploadDirectory); |
59
|
2 |
|
} |
60
|
|
|
|
61
|
2 |
|
private function createRulesPoolCacheDefinition(ContainerBuilder $container, array $config) : string |
62
|
|
|
{ |
63
|
2 |
|
$serviceId = 'obblm.cache.rules'; |
64
|
2 |
|
$default = $container->getDefinition('obblm.cache'); |
65
|
2 |
|
$default->addTag('cache.pool'); |
66
|
2 |
|
$container->setDefinition('obblm.cache', $default); |
67
|
2 |
|
if ($config['caches']) { |
68
|
2 |
|
foreach ($config['caches'] as $part => $options) { |
69
|
2 |
|
if (isset($options['adapter'])) { |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
2 |
|
return $serviceId; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|