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
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class FacileCrossbarHTTPPublisherExtension |
12
|
|
|
* @package Facile\CrossbarHTTPPublisherBundle\DependencyInjection |
13
|
|
|
*/ |
14
|
|
|
class FacileCrossbarHTTPPublisherExtension extends Extension |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritDoc} |
18
|
|
|
*/ |
19
|
|
|
public function load(array $config, ContainerBuilder $container) |
20
|
|
|
{ |
21
|
|
|
$configuration = new Configuration(); |
22
|
|
|
$config = $this->processConfiguration($configuration, $config); |
23
|
|
|
|
24
|
|
|
$this->loadConnections($container, $config); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Registers publisher services in container |
29
|
|
|
* @param ContainerBuilder $container |
30
|
|
|
* @param array $config |
31
|
1 |
|
*/ |
32
|
|
|
private function loadConnections(ContainerBuilder $container, array $config) |
33
|
1 |
|
{ |
34
|
|
|
$factoryName = $this->addFactoryToContainer($container); |
35
|
1 |
|
$genericDefinition = new Definition('Facile\CrossbarHTTPPublisherBundle\Publisher\Publisher'); |
36
|
1 |
|
if (method_exists($genericDefinition, 'setFactory')) { |
37
|
|
|
$genericDefinition->setFactory([new Reference($factoryName), 'createPublisher']); |
38
|
1 |
|
} else { |
39
|
1 |
|
$genericDefinition->setFactoryService($factoryName); |
|
|
|
|
40
|
|
|
$genericDefinition->setFactoryMethod('createPublisher'); |
|
|
|
|
41
|
1 |
|
} |
42
|
1 |
|
|
43
|
|
|
foreach ($config['connections'] as $key => $connection) { |
44
|
|
|
$protocol = $connection['protocol']; |
45
|
|
|
$host = $connection['host']; |
46
|
|
|
$port = $connection['port']; |
47
|
1 |
|
$path = $connection['path']; |
48
|
|
|
$auth_key = $connection['auth_key']; |
49
|
1 |
|
$auth_secret = $connection['auth_secret']; |
50
|
|
|
$hostname = $connection['hostname']; |
51
|
1 |
|
$ignoreSsl = $connection['ssl_ignore']; |
52
|
1 |
|
|
53
|
1 |
|
if ($path[0] !== '/') { |
54
|
1 |
|
$path = '/' . $path; |
55
|
1 |
|
} |
56
|
1 |
|
|
57
|
1 |
|
$definition = clone $genericDefinition; |
58
|
1 |
|
$definition->setArguments([$protocol, $host, $port, $path, $auth_key, $auth_secret, $hostname, $ignoreSsl]); |
59
|
|
|
$container->setDefinition(sprintf('facile.crossbar.publisher.%s', $key), $definition); |
60
|
1 |
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
1 |
|
* @param ContainerBuilder $container |
65
|
1 |
|
* @return string The factory service name inside the container |
66
|
1 |
|
*/ |
67
|
|
|
private function addFactoryToContainer(ContainerBuilder $container) |
68
|
1 |
|
{ |
69
|
1 |
|
$factoryDefinition = new Definition('Facile\CrossbarHTTPPublisherBundle\Publisher\Factory'); |
70
|
1 |
|
$factoryDefinition->setPublic(false); |
71
|
|
|
$factoryName = 'facile.crossbar.publisher.factory'; |
72
|
1 |
|
$container->setDefinition($factoryName, $factoryDefinition); |
73
|
1 |
|
|
74
|
1 |
|
return $factoryName; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.