|
1
|
|
|
<?php |
|
2
|
|
|
namespace GoetasWebservices\Xsd\XsdToPhp\DependencyInjection; |
|
3
|
|
|
|
|
4
|
|
|
use Symfony\Component\Config\FileLocator; |
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
8
|
|
|
|
|
9
|
|
|
class Xsd2PhpExtension extends Extension |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
13
|
|
|
{ |
|
14
|
|
|
$xml = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
15
|
|
|
$xml->load('services.xml'); |
|
16
|
|
|
|
|
17
|
|
|
$configuration = new Configuration(); |
|
18
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
19
|
|
|
foreach ($configs as $subConfig) { |
|
20
|
|
|
$config = array_merge($config, $subConfig); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
$definition = $container->getDefinition('goetas_webservices.xsd2php.naming_convention.' . $config['naming_strategy']); |
|
24
|
|
|
$container->setDefinition('goetas_webservices.xsd2php.naming_convention', $definition); |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
$schemaReader = $container->getDefinition('goetas_webservices.xsd2php.schema_reader'); |
|
28
|
|
|
foreach ($config['known_locations'] as $namespace => $location) { |
|
29
|
|
|
$schemaReader->addMethodCall('addKnownSchemaLocation', [$namespace, $location]); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
foreach (['php', 'jms'] as $type) { |
|
33
|
|
|
$definition = $container->getDefinition('goetas_webservices.xsd2php.path_generator.' . $type . '.' . $config['path_generator']); |
|
34
|
|
|
$container->setDefinition('goetas_webservices.xsd2php.path_generator.' . $type, $definition); |
|
35
|
|
|
|
|
36
|
|
|
$pathGenerator = $container->getDefinition('goetas_webservices.xsd2php.path_generator.' . $type); |
|
37
|
|
|
$pathGenerator->addMethodCall('setTargets', [$config['destinations_' . $type]]); |
|
38
|
|
|
|
|
39
|
|
|
$converter = $container->getDefinition('goetas_webservices.xsd2php.converter.' . $type); |
|
40
|
|
|
foreach ($config['namespaces'] as $xml => $php) { |
|
41
|
|
|
$converter->addMethodCall('addNamespace', [$xml, self::sanitizePhp($php)]); |
|
42
|
|
|
} |
|
43
|
|
|
foreach ($config['aliases'] as $xml => $data) { |
|
44
|
|
|
foreach ($data as $type => $php) { |
|
45
|
|
|
$converter->addMethodCall('addAliasMapType', [$xml, $type, self::sanitizePhp($php)]); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$container->setParameter('goetas_webservices.xsd2php.config', $config); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected static function sanitizePhp($ns) |
|
54
|
|
|
{ |
|
55
|
|
|
return strtr($ns, '/', '\\'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getAlias() |
|
59
|
|
|
{ |
|
60
|
|
|
return 'xsd2php'; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|