1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* apparat-dev |
5
|
|
|
* |
6
|
|
|
* @category Apparat |
7
|
|
|
* @package Apparat\Dev |
8
|
|
|
* @subpackage Apparat\Dev\Infrastructure |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2016 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 © 2016 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 Apparat\Dev\Infrastructure\Mutator\Traits; |
38
|
|
|
|
39
|
|
|
use Apparat\Dev\Application\Utility\Random; |
40
|
|
|
use Apparat\Object\Application\Model\Properties\Domain\Contact as ContactProperties; |
41
|
|
|
use Apparat\Object\Domain\Model\Object\ObjectInterface; |
42
|
|
|
use Apparat\Object\Ports\Types\Object; |
43
|
|
|
use Faker\Generator; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Address mutator trait |
47
|
|
|
* |
48
|
|
|
* @package Apparat\Dev |
49
|
|
|
* @subpackage Apparat\Dev\Infrastructure |
50
|
|
|
* @property Generator $generator |
51
|
|
|
* @method ObjectInterface setRandomAdr(ObjectInterface $object, $probability) |
52
|
|
|
* @method ObjectInterface setRandomPostOfficeBox(ObjectInterface $object, $probability) |
53
|
|
|
* @method ObjectInterface setRandomExtendedAddress(ObjectInterface $object, $probability) |
54
|
|
|
* @method ObjectInterface setRandomStreetAddress(ObjectInterface $object, $probability) |
55
|
|
|
* @method ObjectInterface setRandomLocality(ObjectInterface $object, $probability) |
56
|
|
|
* @method ObjectInterface setRandomRegion(ObjectInterface $object, $probability) |
57
|
|
|
* @method ObjectInterface setRandomPostalCode(ObjectInterface $object, $probability) |
58
|
|
|
* @method ObjectInterface setRandomCountryName(ObjectInterface $object, $probability) |
59
|
|
|
* @method ObjectInterface setRandomLabel(ObjectInterface $object, $probability) |
60
|
|
|
* @method ObjectInterface setRandomGeo(ObjectInterface $object, $probability) |
61
|
|
|
* @method ObjectInterface setRandomLatitude(ObjectInterface $object, $probability) |
62
|
|
|
* @method ObjectInterface setRandomLongitude(ObjectInterface $object, $probability) |
63
|
|
|
* @method ObjectInterface setRandomAltitude(ObjectInterface $object, $probability) |
64
|
|
|
*/ |
65
|
|
|
trait AddressMutatorTrait |
66
|
|
|
{ |
67
|
|
|
/** |
68
|
|
|
* Initialize a postal address |
69
|
|
|
* |
70
|
|
|
* @param ObjectInterface $object Object |
71
|
|
|
*/ |
72
|
1 |
|
protected function initializeAddress(ObjectInterface $object) |
73
|
|
|
{ |
74
|
1 |
|
$this->setRandomPostOfficeBox($object, .2); |
75
|
1 |
|
$this->setRandomExtendedAddress($object, .4); |
76
|
1 |
|
$this->setRandomStreetAddress($object, .9); |
77
|
1 |
|
$this->setLocality($object); |
78
|
1 |
|
$this->setRandomRegion($object, .5); |
79
|
1 |
|
$this->setRandomPostalCode($object, .9); |
80
|
1 |
|
$this->setRandomCountryName($object, .7); |
81
|
1 |
|
$this->setRandomLabel($object, .5); |
82
|
1 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Set an embedded apparat address |
86
|
|
|
* |
87
|
|
|
* @param ObjectInterface $object Contact |
88
|
|
|
* @return ObjectInterface $object Contact |
89
|
|
|
*/ |
90
|
|
|
protected function setAdr(ObjectInterface $object) |
91
|
|
|
{ |
92
|
|
|
return $object->setDomainProperty(ContactProperties::ADR, Random::apparatUrl(Object::ADDRESS)); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Set the post office box |
97
|
|
|
* |
98
|
|
|
* @param ObjectInterface $object Contact |
99
|
|
|
* @return ObjectInterface $object Contact |
100
|
|
|
*/ |
101
|
|
|
protected function setPostOfficeBox(ObjectInterface $object) |
102
|
|
|
{ |
103
|
|
|
return $object->setDomainProperty(ContactProperties::POST_OFFICE_BOX, $this->generator->postcode); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Set the extended address |
108
|
|
|
* |
109
|
|
|
* @param ObjectInterface $object Contact |
110
|
|
|
* @return ObjectInterface $object Contact |
111
|
|
|
*/ |
112
|
1 |
|
protected function setExtendedAddress(ObjectInterface $object) |
113
|
|
|
{ |
114
|
1 |
|
return $object->setDomainProperty(ContactProperties::EXTENDED_ADDRESS, $this->generator->secondaryAddress); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Set the street address |
119
|
|
|
* |
120
|
|
|
* @param ObjectInterface $object Contact |
121
|
|
|
* @return ObjectInterface $object Contact |
122
|
|
|
*/ |
123
|
1 |
|
protected function setStreetAddress(ObjectInterface $object) |
124
|
|
|
{ |
125
|
1 |
|
return $object->setDomainProperty(ContactProperties::STREET_ADDRESS, $this->generator->streetAddress); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Set the locality |
130
|
|
|
* |
131
|
|
|
* @param ObjectInterface $object Contact |
132
|
|
|
* @return ObjectInterface $object Contact |
133
|
|
|
*/ |
134
|
1 |
|
protected function setLocality(ObjectInterface $object) |
135
|
|
|
{ |
136
|
1 |
|
return $object->setDomainProperty(ContactProperties::LOCALITY, $this->generator->city); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Set the region |
141
|
|
|
* |
142
|
|
|
* @param ObjectInterface $object Contact |
143
|
|
|
* @return ObjectInterface $object Contact |
144
|
|
|
*/ |
145
|
1 |
|
protected function setRegion(ObjectInterface $object) |
146
|
|
|
{ |
147
|
1 |
|
return $object->setDomainProperty(ContactProperties::REGION, $this->generator->state); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Set the postal code |
152
|
|
|
* |
153
|
|
|
* @param ObjectInterface $object Contact |
154
|
|
|
* @return ObjectInterface $object Contact |
155
|
|
|
*/ |
156
|
1 |
|
protected function setPostalCode(ObjectInterface $object) |
157
|
|
|
{ |
158
|
1 |
|
return $object->setDomainProperty(ContactProperties::POSTAL_CODE, $this->generator->postcode); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Set the postal code |
163
|
|
|
* |
164
|
|
|
* @param ObjectInterface $object Contact |
165
|
|
|
* @return ObjectInterface $object Contact |
166
|
|
|
*/ |
167
|
1 |
|
protected function setCountryName(ObjectInterface $object) |
168
|
|
|
{ |
169
|
1 |
|
return $object->setDomainProperty(ContactProperties::COUNTRY_NAME, $this->generator->country); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Set the label |
174
|
|
|
* |
175
|
|
|
* @param ObjectInterface $object Contact |
176
|
|
|
* @return ObjectInterface $object Contact |
177
|
|
|
*/ |
178
|
|
|
protected function setLabel(ObjectInterface $object) |
179
|
|
|
{ |
180
|
|
|
return $object->setDomainProperty(ContactProperties::LABEL, $this->generator->address); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Set the geo data |
185
|
|
|
* |
186
|
|
|
* @param ObjectInterface $object Contact |
187
|
|
|
* @return ObjectInterface $object Contact |
188
|
|
|
*/ |
189
|
1 |
|
protected function setGeo(ObjectInterface $object) |
190
|
|
|
{ |
191
|
|
|
// If an apparat URL should be used |
192
|
1 |
|
if (rand(0, 1)) { |
193
|
1 |
|
return $object->setDomainProperty(ContactProperties::GEO, Random::apparatUrl(Object::GEO)); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
// Else: Use a geo URI |
197
|
|
|
$geoUriParts = array_filter([ |
198
|
|
|
$this->generator->latitude, |
199
|
|
|
$this->generator->longitude, |
200
|
|
|
rand(0, 1) ? (rand(-1000, 100000) / 100) : null, |
201
|
|
|
]); |
202
|
|
|
return $object->setDomainProperty(ContactProperties::LABEL, 'geo:'.implode(',', $geoUriParts)); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Set the latitude |
207
|
|
|
* |
208
|
|
|
* @param ObjectInterface $object Contact |
209
|
|
|
* @return ObjectInterface $object Contact |
210
|
|
|
*/ |
211
|
1 |
|
protected function setLatitude(ObjectInterface $object) |
212
|
|
|
{ |
213
|
1 |
|
return $object->setDomainProperty(ContactProperties::LATITUDE, $this->generator->latitude); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Set the longitude |
218
|
|
|
* |
219
|
|
|
* @param ObjectInterface $object Contact |
220
|
|
|
* @return ObjectInterface $object Contact |
221
|
|
|
*/ |
222
|
1 |
|
protected function setLongitude(ObjectInterface $object) |
223
|
|
|
{ |
224
|
1 |
|
return $object->setDomainProperty(ContactProperties::LONGITUDE, $this->generator->longitude); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Set the altitude |
229
|
|
|
* |
230
|
|
|
* @param ObjectInterface $object Contact |
231
|
|
|
* @return ObjectInterface $object Contact |
232
|
|
|
*/ |
233
|
1 |
|
protected function setAltitude(ObjectInterface $object) |
234
|
|
|
{ |
235
|
1 |
|
return $object->setDomainProperty(ContactProperties::ALTITUDE, rand(-1000, 100000) / 100); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|