1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* micrometa |
5
|
|
|
* |
6
|
|
|
* @category Jkphl |
7
|
|
|
* @package Jkphl\Micrometa |
8
|
|
|
* @subpackage Jkphl\Micrometa\Application\Item |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Jkphl\Micrometa\Application\Item; |
38
|
|
|
|
39
|
|
|
use Jkphl\Micrometa\Application\Factory\PropertyListFactoryInterface; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Item |
43
|
|
|
* |
44
|
|
|
* @package Jkphl\Micrometa |
45
|
|
|
* @subpackage Jkphl\Micrometa\Application |
46
|
|
|
* @method PropertyListInterface getProperties() Item properties list |
47
|
|
|
*/ |
48
|
|
|
class Item extends \Jkphl\Micrometa\Domain\Item\Item implements ItemInterface |
49
|
|
|
{ |
50
|
|
|
/** |
51
|
|
|
* Parser format |
52
|
|
|
* |
53
|
|
|
* @var int |
54
|
|
|
*/ |
55
|
|
|
protected $format; |
56
|
|
|
/** |
57
|
|
|
* Item value |
58
|
|
|
* |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
protected $value; |
62
|
|
|
/** |
63
|
|
|
* Nested Items |
64
|
|
|
* |
65
|
|
|
* @var ItemInterface[] |
66
|
|
|
*/ |
67
|
|
|
protected $children; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Item constructor |
71
|
|
|
* |
72
|
|
|
* @param int $format Parser format |
73
|
|
|
* @param PropertyListFactoryInterface $propertyListFactory Property list factory |
74
|
|
|
* @param string|array $type Item type(s) |
75
|
|
|
* @param array[] $properties Item properties |
76
|
|
|
* @param ItemInterface[] $children Nested items |
77
|
|
|
* @param string|null $itemId Item id |
78
|
|
|
* @param string|null $value Item value |
79
|
|
|
*/ |
80
|
17 |
|
public function __construct( |
81
|
|
|
$format, |
82
|
|
|
PropertyListFactoryInterface $propertyListFactory, |
83
|
|
|
$type, |
84
|
|
|
array $properties = [], |
85
|
|
|
array $children = [], |
86
|
|
|
$itemId = null, |
87
|
|
|
$value = null |
88
|
|
|
) { |
89
|
17 |
|
$this->format = $format; |
90
|
17 |
|
parent::__construct($type, $properties, $itemId, $propertyListFactory); |
|
|
|
|
91
|
17 |
|
$this->children = $children; |
92
|
17 |
|
$this->value = $value; |
93
|
17 |
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Return the item value |
97
|
|
|
* |
98
|
|
|
* @return string Item value |
99
|
|
|
*/ |
100
|
1 |
|
public function getValue() |
101
|
|
|
{ |
102
|
1 |
|
return $this->value; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Export the object |
107
|
|
|
* |
108
|
|
|
* @return mixed |
109
|
|
|
*/ |
110
|
1 |
|
public function export() |
111
|
|
|
{ |
112
|
|
|
return (object)[ |
113
|
1 |
|
'format' => $this->getFormat(), |
114
|
1 |
|
'types' => array_map( |
115
|
|
|
function ($type) { |
116
|
1 |
|
return $type->profile.$type->name; |
117
|
1 |
|
}, |
118
|
1 |
|
$this->getType() |
119
|
1 |
|
), |
120
|
1 |
|
'properties' => $this->getProperties()->export(), |
121
|
1 |
|
'items' => array_map( |
122
|
1 |
|
function (ItemInterface $item) { |
123
|
1 |
|
return $item->export(); |
124
|
1 |
|
}, |
125
|
1 |
|
$this->getChildren() |
126
|
1 |
|
) |
127
|
1 |
|
]; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Return the parser format |
132
|
|
|
* |
133
|
|
|
* @return int Parser format |
134
|
|
|
*/ |
135
|
5 |
|
public function getFormat() |
136
|
|
|
{ |
137
|
5 |
|
return $this->format; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Return the nested children |
142
|
|
|
* |
143
|
|
|
* @return ItemInterface[] Nested children |
144
|
|
|
*/ |
145
|
11 |
|
public function getChildren() |
146
|
|
|
{ |
147
|
11 |
|
return $this->children; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.