1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* This file is part of phpFastCache. |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For full copyright and license information, please see the docs/CREDITS.txt file. |
10
|
|
|
* |
11
|
|
|
* @author Georges.L (Geolim4) <[email protected]> |
12
|
|
|
* @author PastisD https://github.com/PastisD |
13
|
|
|
* @author Khoa Bui (khoaofgod) <[email protected]> http://www.phpfastcache.com |
14
|
|
|
* |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace phpFastCache\Bundle\DependencyInjection; |
18
|
|
|
|
19
|
|
|
use phpFastCache\Exceptions\phpFastCacheDriverException; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
use Symfony\Component\Config\FileLocator; |
22
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
23
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class phpFastCacheExtension |
27
|
|
|
* @package phpFastCache\Bundle\DependencyInjection |
28
|
|
|
*/ |
29
|
|
|
class phpFastCacheExtension extends Extension |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* {@inheritDoc} |
33
|
|
|
* |
34
|
|
|
* @throws \phpFastCache\Exceptions\phpFastCacheDriverCheckException |
35
|
|
|
* @throws \phpFastCache\Exceptions\phpFastCacheDriverException |
36
|
|
|
* @throws \Exception |
37
|
|
|
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException |
38
|
|
|
* @throws \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException |
39
|
|
|
* @throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException |
40
|
|
|
*/ |
41
|
|
|
public function load(array $configs, ContainerBuilder $container) |
42
|
|
|
{ |
43
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
44
|
|
|
$loader->load('services.yml'); |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Includes services_dev.yml only |
48
|
|
|
* if we are in debug mode |
49
|
|
|
*/ |
50
|
|
|
if(in_array($container->getParameter('kernel.environment'), ['dev', 'test'])){ |
51
|
|
|
$loader->load('services_dev.yml'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$configuration = new Configuration(); |
55
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
56
|
|
|
|
57
|
|
|
foreach ($config['drivers'] as $name => $driver) { |
58
|
|
|
$class = "phpFastCache\\Drivers\\" . $driver['type'] . '\Driver'; |
59
|
|
|
foreach ($driver['parameters'] as $parameter_name => $parameter) { |
60
|
|
|
if (!$class::isValidOption($parameter_name, $parameter)) { |
61
|
|
|
throw new phpFastCacheDriverException("Option $parameter_name in driver {$driver['type']} doesn't exists"); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$container->setParameter('phpfastcache', $config); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|