1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* RqlQueryRoutesCompilerPass class file |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Graviton\ProxyApiBundle\DependencyInjection\Compiler; |
7
|
|
|
|
8
|
|
|
use Graviton\ProxyApiBundle\Helper\ArrayDefinitionMapper; |
9
|
|
|
use Graviton\ProxyApiBundle\Manager\ProxyManager; |
10
|
|
|
use Graviton\ProxyApiBundle\Model\ProxyModel; |
11
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
13
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
17
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
18
|
|
|
* @link http://swisscom.ch |
19
|
|
|
*/ |
20
|
|
|
class ServicesCompilerPass implements CompilerPassInterface |
21
|
|
|
{ |
22
|
|
|
/** @var ContainerBuilder */ |
23
|
|
|
protected $container; |
24
|
|
|
/** |
25
|
|
|
* Find "allAction" routes and set it to allowed routes for RQL parsing |
26
|
|
|
* |
27
|
|
|
* @param ContainerBuilder $container Container builder |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
2 |
|
public function process(ContainerBuilder $container) |
31
|
|
|
{ |
32
|
2 |
|
$mapper = new ArrayDefinitionMapper(); |
33
|
2 |
|
$this->container = $container; |
34
|
|
|
|
35
|
|
|
/** @var Definition | ProxyManager $proxyManager */ |
36
|
2 |
|
$proxyManager = $container->findDefinition('graviton.proxy_api.proxy_manager'); |
37
|
|
|
|
38
|
|
|
/** @var Definition | ProxyModel $proxyModelOrg */ |
39
|
2 |
|
$proxyModelOrg = $container->findDefinition('graviton.proxy_api.proxy_model'); |
40
|
|
|
|
41
|
|
|
// Create available service objects |
42
|
2 |
|
$services = []; |
43
|
2 |
|
foreach ($container->getParameter('graviton.proxy_api.sources') as $name => $definition) { |
44
|
|
|
// Service definitions |
45
|
2 |
|
$proxyModel = clone $proxyModelOrg; |
46
|
2 |
|
$definition['name'] = $name; |
47
|
2 |
|
$definition = $this->setServiceProcessors($definition); |
48
|
2 |
|
$mapper->map($definition, $proxyModel); |
49
|
2 |
|
$services[$name] = $proxyModel; |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
|
$proxyManager->addMethodCall('addServices', array($services)); |
53
|
2 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Create defaults service if not set. |
57
|
|
|
* |
58
|
|
|
* @param array $definition to be mapped |
59
|
|
|
* @return mixed |
60
|
|
|
*/ |
61
|
2 |
|
private function setServiceProcessors($definition) |
62
|
|
|
{ |
63
|
|
|
// Model definition to Real service definition |
64
|
|
|
$defaults = [ |
65
|
2 |
|
'preProcessorService' => 'graviton.proxy_api.processor.pre', |
66
|
|
|
'proxyProcessorService' => 'graviton.proxy_api.processor.proxy', |
67
|
|
|
'postProcessorService' => 'graviton.proxy_api.processor.post', |
68
|
|
|
]; |
69
|
|
|
|
70
|
2 |
|
foreach ($defaults as $key => $default) { |
71
|
2 |
|
if (!array_key_exists($key, $definition)) { |
72
|
2 |
|
$definition[$key] = $this->container->findDefinition($default); |
73
|
|
|
} else { |
74
|
2 |
|
$definition[$key] = $this->container->findDefinition($definition[$key]); |
75
|
|
|
} |
76
|
|
|
} |
77
|
2 |
|
return $definition; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|