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