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('services.xml'); |
39
|
|
|
|
40
|
|
|
$this->configureRoutes($container, $config); |
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 configureRoutes(ContainerBuilder $container, array $config): void |
50
|
|
|
{ |
51
|
|
|
$container->setParameter('core23_lastfm.auth_success.redirect_route', $config['auth_success']['route']); |
52
|
|
|
$container->setParameter('core23_lastfm.auth_success.redirect_route_params', $config['auth_success']['route_parameters']); |
53
|
|
|
|
54
|
|
|
$container->setParameter('core23_lastfm.auth_error.redirect_route', $config['auth_success']['route']); |
55
|
|
|
$container->setParameter('core23_lastfm.auth_error.redirect_route_params', $config['auth_success']['route_parameters']); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param ContainerBuilder $container |
60
|
|
|
* @param array $config |
61
|
|
|
*/ |
62
|
|
|
private function configureApi(ContainerBuilder $container, array $config): void |
63
|
|
|
{ |
64
|
|
|
$container->setParameter('core23_lastfm.api.app_id', $config['api']['app_id']); |
65
|
|
|
$container->setParameter('core23_lastfm.api.shared_secret', $config['api']['shared_secret']); |
66
|
|
|
$container->setParameter('core23_lastfm.api.endpoint', $config['api']['endpoint']); |
67
|
|
|
$container->setParameter('core23_lastfm.api.auth_url', $config['api']['auth_url']); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param ContainerBuilder $container |
72
|
|
|
* @param array $config |
73
|
|
|
*/ |
74
|
|
|
private function configureHttpClient(ContainerBuilder $container, array $config): void |
75
|
|
|
{ |
76
|
|
|
$container->setAlias('core23_lastfm.http.client', $config['http']['client']); |
77
|
|
|
$container->setAlias('core23_lastfm.http.message_factory', $config['http']['message_factory']); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|