forked from webiny/Entity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntityAttributeBuilder.php
executable file
·178 lines (157 loc) · 4.5 KB
/
EntityAttributeBuilder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* Webiny Framework (http://www.webiny.com/framework)
*
* @copyright Copyright Webiny LTD
*/
namespace Webiny\Component\Entity;
use Webiny\Component\Entity\Attribute\ArrayAttribute;
use Webiny\Component\Entity\Attribute\BooleanAttribute;
use Webiny\Component\Entity\Attribute\CharAttribute;
use Webiny\Component\Entity\Attribute\DateAttribute;
use Webiny\Component\Entity\Attribute\DateTimeAttribute;
use Webiny\Component\Entity\Attribute\DynamicAttribute;
use Webiny\Component\Entity\Attribute\FloatAttribute;
use Webiny\Component\Entity\Attribute\IntegerAttribute;
use Webiny\Component\Entity\Attribute\Many2ManyAttribute;
use Webiny\Component\Entity\Attribute\Many2OneAttribute;
use Webiny\Component\Entity\Attribute\ObjectAttribute;
use Webiny\Component\Entity\Attribute\One2ManyAttribute;
use Webiny\Component\Entity\Attribute\SelectAttribute;
use Webiny\Component\Entity\Attribute\TextAttribute;
use Webiny\Component\StdLib\SingletonTrait;
use Webiny\Component\StdLib\StdObject\ArrayObject\ArrayObject;
/**
* EntityBuilder
* @package Webiny\Component\Entity
*/
class EntityAttributeBuilder
{
protected $entity;
protected $attributes;
protected $attribute;
/**
* @inheritDoc
*/
function __construct(EntityAbstract $entity, ArrayObject $attributes)
{
$this->entity = $entity;
$this->attributes = $attributes;
}
/**
* Create a new attribute
*
* @param $attribute
*
* @return $this
*/
public function attr($attribute)
{
$this->attribute = $attribute;
return $this;
}
/**
* @return BooleanAttribute
*/
public function boolean()
{
return $this->attributes[$this->attribute] = new BooleanAttribute($this->attribute, $this->entity);
}
/**
* @return ArrayAttribute
*/
public function arr()
{
return $this->attributes[$this->attribute] = new ArrayAttribute($this->attribute, $this->entity);
}
/**
* @return ObjectAttribute
*/
public function object()
{
return $this->attributes[$this->attribute] = new ObjectAttribute($this->attribute, $this->entity);
}
/**
* @return IntegerAttribute
*/
public function integer()
{
return $this->attributes[$this->attribute] = new IntegerAttribute($this->attribute, $this->entity);
}
/**
* @return CharAttribute
*/
public function char()
{
return $this->attributes[$this->attribute] = new CharAttribute($this->attribute, $this->entity);
}
/**
* @return TextAttribute
*/
public function text()
{
return $this->attributes[$this->attribute] = new TextAttribute($this->attribute, $this->entity);
}
/**
* @return SelectAttribute
*/
public function select()
{
return $this->attributes[$this->attribute] = new SelectAttribute($this->attribute, $this->entity);
}
/**
* @return DateTimeAttribute
*/
public function datetime()
{
return $this->attributes[$this->attribute] = new DateTimeAttribute($this->attribute, $this->entity);
}
/**
* @return DateAttribute
*/
public function date()
{
return $this->attributes[$this->attribute] = new DateAttribute($this->attribute, $this->entity);
}
/**
* @return FloatAttribute
*/
public function float()
{
return $this->attributes[$this->attribute] = new FloatAttribute($this->attribute, $this->entity);
}
/**
* @return Many2OneAttribute
*/
public function many2one()
{
return $this->attributes[$this->attribute] = new Many2OneAttribute($this->attribute, $this->entity);
}
/**
* @param $relatedAttribute
*
* @return One2ManyAttribute
*/
public function one2many($relatedAttribute)
{
return $this->attributes[$this->attribute] = new One2ManyAttribute($this->attribute, $this->entity, $relatedAttribute);
}
/**
* @param string $collectionName Intermediate collection name
*
* @return Many2ManyAttribute
*/
public function many2many($collectionName)
{
return $this->attributes[$this->attribute] = new Many2ManyAttribute($this->attribute, $this->entity, $collectionName);
}
/**
* @param callable $callable
*
* @return DynamicAttribute
*/
public function dynamic($callable)
{
return $this->attributes[$this->attribute] = new DynamicAttribute($this->attribute, $this->entity, $callable);
}
}