|
1
|
|
|
<?php |
|
2
|
|
|
namespace Graviton\GeneratorBundle\Definition; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
6
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
7
|
|
|
* @link http://swisscom.ch |
|
8
|
|
|
*/ |
|
9
|
|
|
class JsonDefinitionArray implements DefinitionElementInterface |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
private $name; |
|
15
|
|
|
/** |
|
16
|
|
|
* @var DefinitionElementInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
private $element; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Constructor |
|
22
|
|
|
* |
|
23
|
|
|
* @param string $name Field name |
|
24
|
|
|
* @param DefinitionElementInterface $element Array item definition |
|
25
|
|
|
*/ |
|
26
|
21 |
|
public function __construct($name, DefinitionElementInterface $element) |
|
27
|
|
|
{ |
|
28
|
21 |
|
$this->name = $name; |
|
29
|
21 |
|
$this->element = $element; |
|
30
|
21 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return DefinitionElementInterface |
|
34
|
|
|
*/ |
|
35
|
7 |
|
public function getElement() |
|
36
|
|
|
{ |
|
37
|
7 |
|
return $this->element; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns the name of this field |
|
42
|
|
|
* |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
3 |
|
public function getName() |
|
46
|
|
|
{ |
|
47
|
3 |
|
return $this->name; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns the whole definition in array form |
|
52
|
|
|
* |
|
53
|
|
|
* @return array Definition |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function getDefAsArray() |
|
56
|
|
|
{ |
|
57
|
1 |
|
return array_replace( |
|
58
|
1 |
|
$this->element->getDefAsArray(), |
|
59
|
|
|
[ |
|
60
|
1 |
|
'name' => $this->getName(), |
|
61
|
1 |
|
'type' => $this->getType(), |
|
62
|
1 |
|
'doctrineType' => $this->getTypeDoctrine(), |
|
63
|
1 |
|
'serializerType' => $this->getTypeSerializer(), |
|
64
|
|
|
] |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Returns the field type in a doctrine-understandable way.. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string Type |
|
72
|
|
|
*/ |
|
73
|
3 |
|
public function getTypeDoctrine() |
|
74
|
|
|
{ |
|
75
|
3 |
|
return $this->element->getTypeDoctrine().'[]'; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Returns the field type |
|
80
|
|
|
* |
|
81
|
|
|
* @return string Type |
|
82
|
|
|
*/ |
|
83
|
4 |
|
public function getType() |
|
84
|
|
|
{ |
|
85
|
4 |
|
return $this->element->getType().'[]'; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Returns the field type in a serializer-understandable way.. |
|
90
|
|
|
* |
|
91
|
|
|
* @return string Type |
|
92
|
|
|
*/ |
|
93
|
3 |
|
public function getTypeSerializer() |
|
94
|
|
|
{ |
|
95
|
3 |
|
return 'array<'.$this->element->getTypeSerializer().'>'; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|