1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Conveyor package. |
5
|
|
|
* |
6
|
|
|
* (c) Jeroen Fiege <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Webcreate\Conveyor\Config\Definition\Builder; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeBuilder; |
16
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
17
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeParentInterface; |
18
|
|
|
use Symfony\Component\Config\Definition\Builder\ParentNodeDefinitionInterface; |
19
|
|
|
use Webcreate\Conveyor\Config\Definition\StrategyNode; |
20
|
|
|
use Webcreate\Conveyor\Factory\StrategyFactory; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* This class provides a fluent interface for defining an transporter node. |
24
|
|
|
* |
25
|
|
|
* @author Jeroen Fiege |
26
|
|
|
*/ |
27
|
|
|
class StrategyNodeDefinition extends ArrayNodeDefinition implements |
28
|
|
|
ParentNodeDefinitionInterface |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
protected $nodeBuilder; |
31
|
|
|
protected $children; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var StrategyFactory |
35
|
|
|
*/ |
36
|
|
|
protected $strategyFactory; |
37
|
|
|
|
38
|
2 |
|
public function __construct($name, NodeParentInterface $parent = null) |
39
|
|
|
{ |
40
|
2 |
|
parent::__construct($name, $parent); |
41
|
2 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns a node builder to be used to add children and prototype |
45
|
|
|
* |
46
|
|
|
* @return NodeBuilder The node builder |
47
|
|
|
*/ |
48
|
2 |
|
protected function getNodeBuilder() |
49
|
|
|
{ |
50
|
2 |
|
if (null === $this->nodeBuilder) { |
51
|
|
|
$this->nodeBuilder = new NodeBuilder(); |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
return $this->nodeBuilder->setParent($this); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* (non-PHPdoc) |
59
|
|
|
* @see Symfony\Component\Config\Definition\Builder.NodeDefinition::createNode() |
60
|
|
|
*/ |
61
|
2 |
|
protected function createNode() |
62
|
|
|
{ |
63
|
2 |
|
$node = new StrategyNode($this->name, $this->parent); |
|
|
|
|
64
|
2 |
|
$node->setStrategyFactory($this->strategyFactory); |
65
|
|
|
|
66
|
2 |
|
$node->setAddIfNotSet($this->addDefaults); |
67
|
2 |
|
$node->setRequired($this->required); |
68
|
|
|
|
69
|
2 |
|
foreach ($this->children as $child) { |
70
|
2 |
|
$child->parent = $node; |
|
|
|
|
71
|
2 |
|
$node->addChild($child->getNode()); |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
if (null !== $this->normalization) { |
75
|
2 |
|
$node->setNormalizationClosures($this->normalization->before); |
76
|
2 |
|
$node->setXmlRemappings($this->normalization->remappings); |
77
|
|
|
} |
78
|
|
|
|
79
|
2 |
|
if (null !== $this->validation) { |
80
|
|
|
$node->setFinalValidationClosures($this->validation->rules); |
81
|
|
|
} |
82
|
|
|
|
83
|
2 |
|
return $node; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* (non-PHPdoc) |
88
|
|
|
* @see Symfony\Component\Config\Definition\Builder.ParentNodeDefinitionInterface::children() |
89
|
|
|
*/ |
90
|
2 |
|
public function children() |
91
|
|
|
{ |
92
|
2 |
|
return $this->getNodeBuilder(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* (non-PHPdoc) |
97
|
|
|
* @see Symfony\Component\Config\Definition\Builder.ParentNodeDefinitionInterface::append() |
98
|
|
|
*/ |
99
|
2 |
|
public function append(NodeDefinition $node) |
100
|
|
|
{ |
101
|
2 |
|
$this->children[$node->name] = $node->setParent($this); |
102
|
|
|
|
103
|
2 |
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* (non-PHPdoc) |
108
|
|
|
* @see Symfony\Component\Config\Definition\Builder.ParentNodeDefinitionInterface::setBuilder() |
109
|
|
|
*/ |
110
|
2 |
|
public function setBuilder(NodeBuilder $builder) |
111
|
|
|
{ |
112
|
2 |
|
$this->nodeBuilder = $builder; |
113
|
2 |
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Set StrategyFactory |
117
|
|
|
* |
118
|
|
|
* @param StrategyFactory|null $factory |
119
|
|
|
* @return StrategyNodeDefinition |
120
|
|
|
*/ |
121
|
2 |
|
public function setStrategyFactory($factory) |
122
|
|
|
{ |
123
|
2 |
|
$this->strategyFactory = $factory; |
124
|
|
|
|
125
|
2 |
|
return $this; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|