1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the phpflo\phpflo-fbp package. |
4
|
|
|
* |
5
|
|
|
* (c) Marc Aschmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace PhpFlo\Fbp; |
12
|
|
|
|
13
|
|
|
use PhpFlo\Common\DefinitionInterface; |
14
|
|
|
use PhpFlo\Common\FbpDefinitionsInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class FbpDefinition |
18
|
|
|
* |
19
|
|
|
* @package PhpFlo\Fbp |
20
|
|
|
* @author Marc Aschmann <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class FbpDefinition implements DefinitionInterface, FbpDefinitionsInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private $schema; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* FbpDefinition constructor. |
31
|
|
|
* |
32
|
|
|
* @param array $definition |
33
|
|
|
*/ |
34
|
10 |
|
public function __construct(array $definition = []) |
35
|
|
|
{ |
36
|
10 |
|
$this->schema = [ |
37
|
10 |
|
self::PROPERTIES_LABEL => [ |
38
|
10 |
|
'name' => '', |
39
|
10 |
|
], |
40
|
10 |
|
self::INITIALIZERS_LABEL => [], |
41
|
10 |
|
self::PROCESSES_LABEL => [], |
42
|
10 |
|
self::CONNECTIONS_LABEL => [], |
43
|
|
|
]; |
44
|
|
|
|
45
|
10 |
|
$this->definition($definition); |
46
|
10 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param array $definition |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
10 |
|
public function definition(array $definition) |
53
|
|
|
{ |
54
|
10 |
|
$this->schema = array_replace_recursive( |
55
|
10 |
|
$this->schema, |
56
|
|
|
$definition |
57
|
10 |
|
); |
58
|
|
|
|
59
|
10 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
1 |
|
public function properties() |
66
|
|
|
{ |
67
|
1 |
|
return $this->schema[self::PROPERTIES_LABEL]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
1 |
|
public function initializers() |
74
|
|
|
{ |
75
|
1 |
|
return $this->schema[self::INITIALIZERS_LABEL]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
1 |
|
public function processes() |
82
|
|
|
{ |
83
|
1 |
|
return $this->schema[self::PROCESSES_LABEL]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return array |
88
|
|
|
*/ |
89
|
1 |
|
public function connections() |
90
|
|
|
{ |
91
|
1 |
|
return $this->schema[self::CONNECTIONS_LABEL]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
1 |
|
public function name() |
98
|
|
|
{ |
99
|
1 |
|
return $this->schema[self::PROPERTIES_LABEL]['name']; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
8 |
|
public function toArray() |
106
|
|
|
{ |
107
|
8 |
|
return $this->schema; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
1 |
|
public function toJson() |
114
|
|
|
{ |
115
|
1 |
|
return FbpDumper::toJson($this->schema); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
1 |
|
public function toYaml() |
122
|
|
|
{ |
123
|
1 |
|
return FbpDumper::toYaml($this->schema); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
1 |
|
public function toFbp() |
130
|
|
|
{ |
131
|
1 |
|
return FbpDumper::toFbp($this->schema); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|