1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\Xsd\XsdToPhp\Command; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\Config\FileLocator; |
5
|
|
|
use Symfony\Component\Config\Loader\DelegatingLoader; |
6
|
|
|
use Symfony\Component\Config\Loader\LoaderResolver; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
12
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
13
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
14
|
|
|
|
15
|
|
|
class Convert extends Command |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var ContainerInterface |
19
|
|
|
*/ |
20
|
|
|
protected $container; |
21
|
|
|
|
22
|
|
|
public function __construct(ContainerInterface $container) |
23
|
|
|
{ |
24
|
|
|
$this->container = $container; |
25
|
|
|
parent::__construct(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* |
30
|
|
|
* @see Console\Command\Command |
31
|
|
|
*/ |
32
|
|
|
protected function configure() |
33
|
|
|
{ |
34
|
|
|
$this->setName('convert'); |
35
|
|
|
$this->setDescription("Convert a XSD file into PHP classes and JMS serializer metadata files"); |
36
|
|
|
$this->setDefinition(array( |
37
|
|
|
new InputArgument('config', InputArgument::REQUIRED, 'Where is located your XSD definitions'), |
38
|
|
|
new InputArgument('src', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Where is located your XSD definitions'), |
39
|
|
|
)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* |
44
|
|
|
* @see Console\Command\Command |
45
|
|
|
*/ |
46
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
47
|
|
|
{ |
48
|
|
|
$this->loadConfigurations($input->getArgument('config')); |
49
|
|
|
$src = $input->getArgument('src'); |
50
|
|
|
|
51
|
|
|
$schemas = []; |
52
|
|
|
$reader = $this->container->get('goetas_webservices.xsd2php.schema_reader'); |
53
|
|
|
foreach ($src as $file) { |
54
|
|
|
$schemas[] = $reader->readFile($file); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
foreach (['php', 'jms'] as $type) { |
58
|
|
|
$converter = $this->container->get('goetas_webservices.xsd2php.converter.' . $type); |
59
|
|
|
$items = $converter->convert($schemas); |
60
|
|
|
|
61
|
|
|
$writer = $this->container->get('goetas_webservices.xsd2php.writer.' . $type); |
62
|
|
|
$writer->write($items); |
63
|
|
|
} |
64
|
|
|
return count($items) ? 0 : 255; |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function loadConfigurations($configFile) |
68
|
|
|
{ |
69
|
|
|
$locator = new FileLocator('.'); |
70
|
|
|
$yaml = new YamlFileLoader($this->container, $locator); |
|
|
|
|
71
|
|
|
$xml = new XmlFileLoader($this->container, $locator); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$delegatingLoader = new DelegatingLoader(new LoaderResolver(array($yaml, $xml))); |
74
|
|
|
$delegatingLoader->load($configFile); |
75
|
|
|
|
76
|
|
|
$this->container->compile(); |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: