|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Contains class XsdWiring. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.5 |
|
6
|
|
|
* |
|
7
|
|
|
* LICENSE: |
|
8
|
|
|
* This file is part of Yet Another Php Eve Api Library also know as Yapeal |
|
9
|
|
|
* which can be used to access the Eve Online API data and place it into a |
|
10
|
|
|
* database. |
|
11
|
|
|
* Copyright (C) 2016 Michael Cummings |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software: you can redistribute it and/or modify it |
|
14
|
|
|
* under the terms of the GNU Lesser General Public License as published by the |
|
15
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
|
16
|
|
|
* option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
19
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
|
21
|
|
|
* for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
24
|
|
|
* along with this program. If not, see |
|
25
|
|
|
* <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* |
|
27
|
|
|
* You should be able to find a copy of this license in the LICENSE.md file. A |
|
28
|
|
|
* copy of the GNU GPL should also be available in the GNU-GPL.md file. |
|
29
|
|
|
* |
|
30
|
|
|
* @copyright 2016 Michael Cummings |
|
31
|
|
|
* @license LGPL-3.0+ |
|
32
|
|
|
* @author Michael Cummings <[email protected]> |
|
33
|
|
|
*/ |
|
34
|
|
|
namespace Yapeal\Configuration; |
|
35
|
|
|
|
|
36
|
|
|
use Twig_Environment; |
|
37
|
|
|
use Twig_Loader_Filesystem; |
|
38
|
|
|
use Twig_SimpleFilter; |
|
39
|
|
|
use Yapeal\Container\ContainerInterface; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Class XsdWiring. |
|
43
|
|
|
*/ |
|
44
|
|
|
class XsdWiring implements WiringInterface |
|
45
|
|
|
{ |
|
46
|
|
|
/** |
|
47
|
|
|
* @param ContainerInterface $dic |
|
48
|
|
|
* |
|
49
|
|
|
* @return self Fluent interface. |
|
50
|
|
|
* @throws \LogicException |
|
51
|
|
|
* @throws \InvalidArgumentException |
|
52
|
|
|
*/ |
|
53
|
|
|
public function wire(ContainerInterface $dic) |
|
54
|
|
|
{ |
|
55
|
|
|
if (empty($dic['Yapeal.Xsd.Creator'])) { |
|
56
|
|
|
$dic['Yapeal.Xsd.Creator'] = $dic->factory( |
|
57
|
|
|
function ($dic) { |
|
58
|
|
|
$loader = new Twig_Loader_Filesystem($dic['Yapeal.Xsd.dir']); |
|
59
|
|
|
$twig = new Twig_Environment( |
|
60
|
|
|
$loader, ['debug' => true, 'strict_variables' => true, 'autoescape' => false] |
|
61
|
|
|
); |
|
62
|
|
|
$filter = new Twig_SimpleFilter( |
|
63
|
|
|
'ucFirst', function ($value) { |
|
64
|
|
|
return ucfirst($value); |
|
65
|
|
|
} |
|
66
|
|
|
); |
|
67
|
|
|
$twig->addFilter($filter); |
|
68
|
|
|
$filter = new Twig_SimpleFilter( |
|
69
|
|
|
'lcFirst', function ($value) { |
|
70
|
|
|
return lcfirst($value); |
|
71
|
|
|
} |
|
72
|
|
|
); |
|
73
|
|
|
$twig->addFilter($filter); |
|
74
|
|
|
/** |
|
75
|
|
|
* @var \Yapeal\Xsd\Creator $create |
|
76
|
|
|
*/ |
|
77
|
|
|
$create = new $dic['Yapeal.Xsd.create']($twig, $dic['Yapeal.Xsd.dir']); |
|
78
|
|
|
if (array_key_exists('Yapeal.Create.overwrite', $dic)) { |
|
79
|
|
|
$create->setOverwrite($dic['Yapeal.Create.overwrite']); |
|
80
|
|
|
} |
|
81
|
|
|
return $create; |
|
82
|
|
|
} |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
if (empty($dic['Yapeal.Xsd.Validator'])) { |
|
86
|
|
|
$dic['Yapeal.Xsd.Validator'] = $dic->factory( |
|
87
|
|
|
function ($dic) { |
|
88
|
|
|
return new $dic['Yapeal.Xsd.validate']($dic['Yapeal.Xsd.dir']); |
|
89
|
|
|
} |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
if (!isset($dic['Yapeal.Event.Mediator'])) { |
|
93
|
|
|
$mess = 'Tried to call Mediator before it has been added'; |
|
94
|
|
|
throw new \LogicException($mess); |
|
95
|
|
|
} |
|
96
|
|
|
/** |
|
97
|
|
|
* @var \Yapeal\Event\MediatorInterface $mediator |
|
98
|
|
|
*/ |
|
99
|
|
|
$mediator = $dic['Yapeal.Event.Mediator']; |
|
100
|
|
|
$mediator->addServiceSubscriberByEventList( |
|
101
|
|
|
'Yapeal.Xsd.Creator', |
|
102
|
|
|
['Yapeal.EveApi.create' => ['createXsd', 'last']] |
|
103
|
|
|
); |
|
104
|
|
|
$mediator->addServiceSubscriberByEventList( |
|
105
|
|
|
'Yapeal.Xsd.Validator', |
|
106
|
|
|
['Yapeal.EveApi.validate' => ['validateEveApi', 'last']] |
|
107
|
|
|
); |
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|