|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the AMFWebServicesClientBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Amine Fattouch <http://github.com/fattouchsquall> |
|
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 AMF\WebServicesClientBundle\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Pass of compilation to register Rest webservices. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Mohamed Amine Fattouch <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class RegisterRestWebServicesPass implements CompilerPassInterface |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Register rest webservices definition. |
|
30
|
|
|
* |
|
31
|
|
|
* @param ContainerBuilder $container Instance of container. |
|
32
|
|
|
*/ |
|
33
|
|
|
public function process(ContainerBuilder $container) |
|
34
|
|
|
{ |
|
35
|
|
|
if ($container->hasParameter('amf_web_services_client.rest.endpoints') === false) { |
|
36
|
|
|
return; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$endpoints = $container->getParameter('amf_web_services_client.rest.endpoints'); |
|
40
|
|
|
foreach ($endpoints as $key => $endpoint) { |
|
41
|
|
|
$restEndpoint = 'amf_web_services_client.rest.'.$key; |
|
42
|
|
|
$container->setDefinition($restEndpoint, new DefinitionDecorator('amf_web_services_client.rest.endpoint')) |
|
43
|
|
|
->setClass($endpoint['class']) |
|
44
|
|
|
->replaceArgument(3, $this->addUrlDefinition($container, $key, $url)) |
|
|
|
|
|
|
45
|
|
|
->replaceArgument(4, $this->addWsseDefinition($container, $key, $wsse)) |
|
|
|
|
|
|
46
|
|
|
->replaceArgument(5, $endpoint['request_format']) |
|
47
|
|
|
->replaceArgument(6, $endpoint['response_format']); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Adds wsse defintion to container only if it's enabled.. |
|
53
|
|
|
* |
|
54
|
|
|
* @param ContainerInterface $container |
|
55
|
|
|
* @param string $key |
|
56
|
|
|
* @param array $wsse |
|
57
|
|
|
* |
|
58
|
|
|
* @return Reference|null |
|
59
|
|
|
*/ |
|
60
|
|
View Code Duplication |
private function addWsseDefinition(ContainerInterface $container, $key, array $wsse) |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
if (($wsse['enabled'] === true)) { |
|
63
|
|
|
$restWsse = 'amf_web_services_client.rest.wsse.'.$key; |
|
64
|
|
|
$container |
|
|
|
|
|
|
65
|
|
|
->setDefinition($restWsse, new DefinitionDecorator('amf_web_services_client.rest.wsse')) |
|
66
|
|
|
->replaceArgument(0, $wsse['username']) |
|
67
|
|
|
->replaceArgument(1, $wsse['password']) |
|
68
|
|
|
->replaceArgument(2, $wsse['options']); |
|
69
|
|
|
|
|
70
|
|
|
return new Reference($restWsse); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return null; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Adds url defintion to container only if it's enabled. |
|
78
|
|
|
* |
|
79
|
|
|
* @param ContainerInterface $container |
|
80
|
|
|
* @param string $key |
|
81
|
|
|
* @param array $wsse |
|
|
|
|
|
|
82
|
|
|
* |
|
83
|
|
|
* @return Reference|null |
|
84
|
|
|
*/ |
|
85
|
|
View Code Duplication |
private function addUrlDefinition(ContainerInterface $container, $key, $url) |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
if (($url['enabled'] === true)) { |
|
88
|
|
|
$restUrl = 'amf_web_services_client.rest.url.'.$key; |
|
89
|
|
|
$container |
|
|
|
|
|
|
90
|
|
|
->setDefinition($restUrl, new DefinitionDecorator('amf_web_services_client.rest.url')) |
|
91
|
|
|
->replaceArgument(0, $url['hostname']) |
|
92
|
|
|
->replaceArgument(1, $url['scheme']) |
|
93
|
|
|
->replaceArgument(2, $url['port']) |
|
94
|
|
|
->replaceArgument(3, $url['query_delimiter']); |
|
95
|
|
|
|
|
96
|
|
|
return new Reference($restUrl); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return null; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.