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
|
|
|
public function getAlias() |
22
|
|
|
{ |
23
|
|
|
return 'core23_lastfm'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
27
|
|
|
{ |
28
|
|
|
$configuration = new Configuration(); |
29
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
30
|
|
|
|
31
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
32
|
|
|
$loader->load('action.xml'); |
33
|
|
|
$loader->load('services.xml'); |
34
|
|
|
|
35
|
|
|
$this->configureApi($container, $config); |
36
|
|
|
$this->configureHttpClient($container, $config); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
private function configureApi(ContainerBuilder $container, array $config): void |
40
|
|
|
{ |
41
|
|
|
$container->setParameter('core23_lastfm.api.app_id', $config['api']['app_id']); |
42
|
|
|
$container->setParameter('core23_lastfm.api.shared_secret', $config['api']['shared_secret']); |
43
|
|
|
$container->setParameter('core23_lastfm.api.endpoint', $config['api']['endpoint']); |
44
|
|
|
$container->setParameter('core23_lastfm.api.auth_url', $config['api']['auth_url']); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function configureHttpClient(ContainerBuilder $container, array $config): void |
48
|
|
|
{ |
49
|
|
|
$container->setAlias('core23_lastfm.http.client', $config['http']['client']); |
50
|
|
|
$container->setAlias('core23_lastfm.http.message_factory', $config['http']['message_factory']); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|