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\ShariffBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Core23\ShariffBundle\Service\Facebook; |
15
|
|
|
use Symfony\Component\Config\FileLocator; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
18
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
19
|
|
|
|
20
|
|
|
final class Core23ShariffExtension extends Extension |
21
|
|
|
{ |
22
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
23
|
|
|
{ |
24
|
|
|
$configuration = new Configuration(); |
25
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
26
|
|
|
|
27
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
28
|
|
|
$loader->load('action.xml'); |
29
|
|
|
$loader->load('block.xml'); |
30
|
|
|
$loader->load('services.xml'); |
31
|
|
|
|
32
|
|
|
$this->configureAliases($container, $config); |
33
|
|
|
$this->configureDomains($container, $config); |
34
|
|
|
$this->configureServices($container, $config); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
private function configureServices(ContainerBuilder $container, array $config): void |
38
|
|
|
{ |
39
|
|
|
$services = $config['options']['services']; |
40
|
|
|
$facebook = $config['services']['facebook'] ?? null; |
41
|
|
|
|
42
|
|
|
if ( |
43
|
|
|
!isset($facebook['app_id'], $facebook['secret']) || |
44
|
|
|
null === $facebook['app_id'] || null === $facebook['secret'] |
45
|
|
|
) { |
46
|
|
|
if (false !== ($key = array_search('facebook', $services, true))) { |
47
|
|
|
unset($services[$key]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$container->removeDefinition(Facebook::class); |
51
|
|
|
} else { |
52
|
|
|
$container->setParameter('core23_shariff.service.facebook.app_id', $facebook['app_id']); |
53
|
|
|
$container->setParameter('core23_shariff.service.facebook.secret', $facebook['secret']); |
54
|
|
|
$container->setParameter('core23_shariff.service.facebook.version', $facebook['version'] ?? null); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$container->setParameter('core23_shariff.services', array_values($services)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function configureAliases(ContainerBuilder $container, array $config): void |
61
|
|
|
{ |
62
|
|
|
$container->setAlias('core23_shariff.cache', $config['cache']); |
63
|
|
|
$container->setAlias('core23_shariff.http_client', $config['http_client']); |
64
|
|
|
$container->setAlias('core23_shariff.request_factory', $config['request_factory']); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function configureDomains(ContainerBuilder $container, array $config): void |
68
|
|
|
{ |
69
|
|
|
$container->setParameter('core23_shariff.domains', $config['options']['domains']); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|