1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\SoapServices\SoapClient\DependencyInjection; |
3
|
|
|
|
4
|
|
|
use Psr\Log\NullLogger; |
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
8
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
9
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
10
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
11
|
|
|
|
12
|
|
|
class SoapClientExtension extends Extension implements PrependExtensionInterface |
13
|
|
|
{ |
14
|
2 |
|
public function load(array $configs, ContainerBuilder $container) |
15
|
|
|
{ |
16
|
2 |
|
$config = $this->processConfiguration(new Configuration(), $configs); |
17
|
2 |
|
foreach ($configs as $subConfig) { |
18
|
2 |
|
$config = array_merge($config, $subConfig); |
19
|
2 |
|
} |
20
|
|
|
|
21
|
2 |
|
$container->setParameter('goetas_webservices.soap_client.config', $config); |
22
|
2 |
|
$container->setParameter('goetas_webservices.soap_client.unwrap_returns', $config['unwrap_returns']); |
23
|
|
|
|
24
|
2 |
|
$xml = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
25
|
2 |
|
$xml->load('services.xml'); |
26
|
|
|
|
27
|
|
|
|
28
|
2 |
|
$container->setDefinition('logger', new Definition(NullLogger::class)); |
29
|
|
|
|
30
|
2 |
|
$definition = $container->getDefinition('goetas_webservices.xsd2php.path_generator.jms.' . $config['path_generator']); |
31
|
2 |
|
$container->setDefinition('goetas_webservices.xsd2php.path_generator.jms', clone $definition); |
32
|
|
|
|
33
|
2 |
|
$definition = $container->getDefinition('goetas_webservices.xsd2php.path_generator.php.' . $config['path_generator']); |
34
|
2 |
|
$container->setDefinition('goetas_webservices.xsd2php.path_generator.php', clone $definition); |
35
|
|
|
|
36
|
|
|
|
37
|
2 |
|
$pathGenerator = $container->getDefinition('goetas_webservices.xsd2php.path_generator.jms'); |
38
|
2 |
|
$pathGenerator->addMethodCall('setTargets', [$config['destinations_jms']]); |
39
|
|
|
|
40
|
2 |
|
$pathGenerator = $container->getDefinition('goetas_webservices.xsd2php.path_generator.php'); |
41
|
2 |
|
$pathGenerator->addMethodCall('setTargets', [$config['destinations_php']]); |
42
|
|
|
|
43
|
|
|
|
44
|
2 |
|
foreach (['php', 'jms'] as $type) { |
45
|
2 |
|
$converter = $container->getDefinition('goetas_webservices.xsd2php.converter.' . $type); |
46
|
2 |
|
foreach ($config['namespaces'] as $xml => $php) { |
47
|
2 |
|
$converter->addMethodCall('addNamespace', [$xml, self::sanitizePhp($php)]); |
48
|
2 |
|
} |
49
|
2 |
|
foreach ($config['aliases'] as $xml => $data) { |
50
|
2 |
|
foreach ($data as $type => $php) { |
51
|
2 |
|
$converter->addMethodCall('addAliasMapType', [$xml, $type, self::sanitizePhp($php)]); |
52
|
2 |
|
} |
53
|
2 |
|
} |
54
|
2 |
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
2 |
|
$definition = $container->getDefinition('goetas_webservices.xsd2php.naming_convention.' . $config['naming_strategy']); |
58
|
2 |
|
$container->setDefinition('goetas_webservices.xsd2php.naming_convention', $definition); |
59
|
|
|
|
60
|
|
|
////////// |
61
|
|
|
|
62
|
2 |
|
$metadataGenerator = $container->getDefinition('goetas_webservices.soap_client.metadata.generator'); |
63
|
2 |
|
foreach ($config['alternative_endpoints'] as $service => $data) { |
64
|
2 |
|
foreach ($data as $port => $endPoint) { |
65
|
2 |
|
$metadataGenerator->addMethodCall('addAlternativeEndpoint', [$service, $port, $endPoint]); |
66
|
2 |
|
} |
67
|
2 |
|
} |
68
|
2 |
|
$keys = ['headers', 'parts', 'messages']; |
|
|
|
|
69
|
|
|
//$metadataGenerator->addMethodCall('setBaseNs', [array_intersect_key($config, array_combine($keys, $keys))]); |
|
|
|
|
70
|
2 |
|
$metadataGenerator->addMethodCall('setUnwrap', [$config['unwrap_returns']]); |
71
|
2 |
|
$metadataGenerator->replaceArgument(1, $config['namespaces']); |
72
|
|
|
|
73
|
2 |
|
$writer = $container->getDefinition('goetas_webservices.soap_client.stub.client_generator'); |
74
|
2 |
|
$writer->addMethodCall('setUnwrap', [$config['unwrap_returns']]); |
75
|
|
|
|
76
|
|
|
|
77
|
2 |
|
$forProduction = !!$container->getParameter('goetas_webservices.soap_client.metadata'); |
78
|
|
|
|
79
|
2 |
|
$readerName = 'goetas_webservices.soap_client.metadata_loader.' . ($forProduction ? 'array' : 'dev'); |
80
|
2 |
|
$container->setAlias('goetas_webservices.soap_client.metadata_reader', $readerName); |
81
|
|
|
|
82
|
2 |
|
} |
83
|
|
|
|
84
|
2 |
|
protected static function sanitizePhp($ns) |
85
|
|
|
{ |
86
|
2 |
|
return strtr($ns, '/', '\\'); |
87
|
|
|
} |
88
|
|
|
|
89
|
2 |
|
public function getAlias() |
90
|
|
|
{ |
91
|
2 |
|
return 'soap_client'; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Allow an extension to prepend the extension configurations. |
96
|
|
|
* |
97
|
|
|
* @param ContainerBuilder $container |
98
|
|
|
*/ |
99
|
2 |
|
public function prepend(ContainerBuilder $container) |
100
|
|
|
{ |
101
|
2 |
|
$container->prependExtensionConfig('goetas_soap_client', []); |
102
|
2 |
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.