|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* AnimeDb package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Peter Gribanov <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2011, Peter Gribanov |
|
7
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace AnimeDb\Bundle\AniDbBrowserBundle\DependencyInjection; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
12
|
|
|
use Symfony\Component\Config\FileLocator; |
|
13
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
15
|
|
|
|
|
16
|
|
|
class AnimeDbAniDbBrowserExtension extends Extension |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @param array $configs |
|
20
|
|
|
* @param ContainerBuilder $container |
|
21
|
|
|
*/ |
|
22
|
11 |
|
public function load(array $configs, ContainerBuilder $container) |
|
23
|
|
|
{ |
|
24
|
11 |
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
25
|
11 |
|
$loader->load('parameters.yml'); |
|
26
|
11 |
|
$loader->load('services.yml'); |
|
27
|
|
|
|
|
28
|
11 |
|
$config = $this->processConfiguration(new Configuration(), $configs); |
|
29
|
|
|
|
|
30
|
|
|
$container |
|
31
|
4 |
|
->getDefinition('anime_db.ani_db.browser.client.guzzle.request_configurator') |
|
32
|
4 |
|
->addMethodCall('setAppVersion', [$config['app']['version']]) |
|
33
|
4 |
|
->addMethodCall('setAppClient', [$config['app']['client']]) |
|
34
|
4 |
|
->addMethodCall('setAppCode', [$config['app']['code']]); |
|
35
|
|
|
|
|
36
|
4 |
|
$container->setAlias('anime_db.ani_db.browser.client', $this->getRealServiceName($config['client'])); |
|
37
|
4 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $name |
|
41
|
|
|
* |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
4 |
|
protected function getRealServiceName($name) |
|
45
|
|
|
{ |
|
46
|
4 |
|
if (in_array($name, ['cache', 'guzzle'])) { |
|
47
|
3 |
|
return 'anime_db.ani_db.browser.client.'.$name; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
return $name; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|