|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Facile\CrossbarHTTPPublisherBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
9
|
|
|
use Facile\CrossbarHTTPPublisherBundle\Publisher\Publisher; |
|
10
|
|
|
use Facile\CrossbarHTTPPublisherBundle\Publisher\Factory; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class FacileCrossbarHTTPPublisherExtension |
|
14
|
|
|
* @package Facile\CrossbarHTTPPublisherBundle\DependencyInjection |
|
15
|
|
|
*/ |
|
16
|
|
|
class FacileCrossbarHTTPPublisherExtension extends Extension |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritDoc} |
|
20
|
|
|
*/ |
|
21
|
1 |
|
public function load(array $config, ContainerBuilder $container) |
|
22
|
|
|
{ |
|
23
|
1 |
|
$configuration = new Configuration(); |
|
24
|
1 |
|
$config = $this->processConfiguration($configuration, $config); |
|
25
|
|
|
|
|
26
|
1 |
|
$this->loadConnections($container, $config); |
|
27
|
1 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Registers publisher services in container |
|
31
|
|
|
* @param ContainerBuilder $container |
|
32
|
|
|
* @param array $config |
|
33
|
|
|
*/ |
|
34
|
1 |
|
private function loadConnections(ContainerBuilder $container, array $config) |
|
35
|
|
|
{ |
|
36
|
1 |
|
$factoryName = $this->addFactoryToContainer($container); |
|
37
|
1 |
|
$genericDefinition = new Definition(Publisher::class); |
|
38
|
1 |
|
$genericDefinition->setFactory([new Reference($factoryName), 'createPublisher']); |
|
39
|
|
|
|
|
40
|
1 |
|
foreach ($config['connections'] as $key => $connection) { |
|
41
|
1 |
|
$protocol = $connection['protocol']; |
|
42
|
1 |
|
$host = $connection['host']; |
|
43
|
1 |
|
$port = $connection['port']; |
|
44
|
1 |
|
$path = $connection['path']; |
|
45
|
1 |
|
$auth_key = $connection['auth_key']; |
|
46
|
1 |
|
$auth_secret = $connection['auth_secret']; |
|
47
|
1 |
|
$hostname = $connection['hostname']; |
|
48
|
1 |
|
$ignoreSsl = $connection['ssl_ignore']; |
|
49
|
|
|
|
|
50
|
1 |
|
if ($path[0] !== '/') { |
|
51
|
|
|
$path = '/' . $path; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
$definition = clone $genericDefinition; |
|
55
|
1 |
|
$definition->setArguments([$protocol, $host, $port, $path, $auth_key, $auth_secret, $hostname, $ignoreSsl]); |
|
56
|
1 |
|
$definition->setPublic(true); |
|
57
|
1 |
|
$container->setDefinition(sprintf('facile.crossbar.publisher.%s', $key), $definition); |
|
58
|
|
|
} |
|
59
|
1 |
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param ContainerBuilder $container |
|
63
|
|
|
* @return string The factory service name inside the container |
|
64
|
|
|
*/ |
|
65
|
1 |
|
private function addFactoryToContainer(ContainerBuilder $container) |
|
66
|
|
|
{ |
|
67
|
1 |
|
$factoryDefinition = new Definition(Factory::class); |
|
68
|
1 |
|
$factoryDefinition->setPublic(false); |
|
69
|
1 |
|
$factoryName = 'facile.crossbar.publisher.factory'; |
|
70
|
1 |
|
$container->setDefinition($factoryName, $factoryDefinition); |
|
71
|
|
|
|
|
72
|
1 |
|
return $factoryName; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|