1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* (c) Christian Gripp <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Core23\LastFmBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
17
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
18
|
|
|
|
19
|
|
|
final class Core23LastFmExtension extends Extension |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function getAlias() |
25
|
|
|
{ |
26
|
|
|
return 'core23_lastfm'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
33
|
|
|
{ |
34
|
|
|
$configuration = new Configuration(); |
35
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
36
|
|
|
|
37
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
38
|
|
|
$loader->load('action.xml'); |
39
|
|
|
$loader->load('services.xml'); |
40
|
|
|
|
41
|
|
|
$this->configureApi($container, $config); |
42
|
|
|
$this->configureHttpClient($container, $config); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param ContainerBuilder $container |
47
|
|
|
* @param array $config |
48
|
|
|
*/ |
49
|
|
|
private function configureApi(ContainerBuilder $container, array $config): void |
50
|
|
|
{ |
51
|
|
|
$container->setParameter('core23_lastfm.api.app_id', $config['api']['app_id']); |
52
|
|
|
$container->setParameter('core23_lastfm.api.shared_secret', $config['api']['shared_secret']); |
53
|
|
|
$container->setParameter('core23_lastfm.api.endpoint', $config['api']['endpoint']); |
54
|
|
|
$container->setParameter('core23_lastfm.api.auth_url', $config['api']['auth_url']); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param ContainerBuilder $container |
59
|
|
|
* @param array $config |
60
|
|
|
*/ |
61
|
|
|
private function configureHttpClient(ContainerBuilder $container, array $config): void |
62
|
|
|
{ |
63
|
|
|
$container->setAlias('core23_lastfm.http.client', $config['http']['client']); |
64
|
|
|
$container->setAlias('core23_lastfm.http.message_factory', $config['http']['message_factory']); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|