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; |
38
|
|
|
|
39
|
|
|
use Apparat\Dev\Application\Utility\Random; |
40
|
|
|
use Apparat\Dev\Infrastructure\Mutator\Traits\AddressMutatorTrait; |
41
|
|
|
use Apparat\Dev\Infrastructure\Mutator\Traits\NameMutatorTrait; |
42
|
|
|
use Apparat\Object\Application\Model\Properties\Domain\Contact as ContactProperties; |
43
|
|
|
use Apparat\Object\Domain\Model\Object\ObjectInterface; |
44
|
|
|
use Apparat\Object\Ports\Types\Object; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Contact object mutator |
48
|
|
|
* |
49
|
|
|
* @package Apparat\Dev |
50
|
|
|
* @subpackage Apparat\Dev\Infrastructure |
51
|
|
|
* @method ObjectInterface setRandomEmail(ObjectInterface $object, $probability) |
52
|
|
|
* @method ObjectInterface setRandomLogo(ObjectInterface $object, $probability) |
53
|
|
|
* @method ObjectInterface setRandomPhoto(ObjectInterface $object, $probability) |
54
|
|
|
* @method ObjectInterface setRandomUrl(ObjectInterface $object, $probability) |
55
|
|
|
* @method ObjectInterface setRandomTel(ObjectInterface $object, $probability) |
56
|
|
|
* @method ObjectInterface setRandomNote(ObjectInterface $object, $probability) |
57
|
|
|
* @method ObjectInterface setRandomBday(ObjectInterface $object, $probability) |
58
|
|
|
* @method ObjectInterface setRandomKey(ObjectInterface $object, $probability) |
59
|
|
|
* @method ObjectInterface setRandomOrg(ObjectInterface $object, $probability) |
60
|
|
|
* @method ObjectInterface setRandomJobTitle(ObjectInterface $object, $probability) |
61
|
|
|
* @method ObjectInterface setRandomRole(ObjectInterface $object, $probability) |
62
|
|
|
* @method ObjectInterface setRandomImpp(ObjectInterface $object, $probability) |
63
|
|
|
* @method ObjectInterface setRandomSex(ObjectInterface $object, $probability) |
64
|
|
|
* @method ObjectInterface setRandomGenderIdentity(ObjectInterface $object, $probability) |
65
|
|
|
* @method ObjectInterface setRandomAnniversary(ObjectInterface $object, $probability) |
66
|
|
|
*/ |
67
|
|
|
class ContactObjectMutator extends AbstractObjectMutator |
68
|
|
|
{ |
69
|
|
|
/** |
70
|
|
|
* Use traits |
71
|
|
|
*/ |
72
|
|
|
use NameMutatorTrait, AddressMutatorTrait; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Initialize the contact |
76
|
|
|
* |
77
|
|
|
* @param ObjectInterface $object Contact |
78
|
|
|
* @return ObjectInterface Contact |
79
|
|
|
*/ |
80
|
1 |
|
public function initialize(ObjectInterface $object) |
81
|
|
|
{ |
82
|
1 |
|
$this->setRandomLocation($object, .6); // p-location |
83
|
1 |
|
$this->setRandomDescription($object, .2); // p-summary |
84
|
1 |
|
$this->setRandomCategories($object, .4); // p-category |
85
|
1 |
|
$this->setRandomKeywords($object, .7); |
86
|
1 |
|
$this->setAuthors($object); |
87
|
|
|
|
88
|
|
|
// p-name - full/formatted name of the person or organisation (automatically set via the various name facets) |
89
|
1 |
|
$this->setRandomHonorificPrefix($object, .3); // p-honorific-prefix - e.g. Mrs., Mr. or Dr. |
90
|
1 |
|
$this->setGivenName($object); // p-given-name - given (often first) name |
91
|
1 |
|
$this->setRandomNickname($object, .3); // p-nickname - nickname/alias/handle |
92
|
1 |
|
$this->setRandomAdditionalName($object, .2); // p-additional-name - other/middle name |
93
|
1 |
|
$this->setRandomFamilyName($object, .9);// p-family-name - family (often last) name |
94
|
1 |
|
$this->setRandomHonorificSuffix($object, .1); // p-honorific-suffix - e.g. Ph.D, Esq. |
95
|
1 |
|
$this->setSortString($object); // p-sort-string - string to sort by |
96
|
|
|
|
97
|
1 |
|
$this->setRandomEmail($object, .5); // u-email - email address |
98
|
1 |
|
$this->setRandomLogo($object, .2); // u-logo - a logo representing the person or organisation |
99
|
1 |
|
$this->setRandomPhoto($object, .4); // u-photo |
100
|
1 |
|
$this->setRandomUrl($object, .7); // u-url - home page |
101
|
|
|
|
102
|
1 |
|
$this->happens(.4) ? |
103
|
|
|
$this->setRandomAdr($object, .8) : // p-adr - postal address, optionally embed an h-adr |
104
|
1 |
|
$this->initializeAddress($object); |
105
|
1 |
|
$this->happens(.5) ? |
106
|
1 |
|
$this->setRandomGeo($object, .8) : // u-geo |
107
|
1 |
|
$this->initializeLatitudeLongitudeAltitude($object); |
108
|
|
|
|
109
|
1 |
|
$this->setRandomTel($object, .5); |
110
|
1 |
|
$this->setRandomNote($object, .3); |
111
|
1 |
|
$this->setRandomBday($object, .3); |
112
|
|
|
|
113
|
1 |
|
$this->setRandomKey($object, .2); |
114
|
1 |
|
$this->setRandomOrg($object, .5); |
115
|
1 |
|
$this->setRandomJobTitle($object, .4); |
116
|
1 |
|
$this->setRandomRole($object, .4); |
117
|
|
|
|
118
|
1 |
|
$this->setRandomImpp($object, .1); |
119
|
1 |
|
$this->setRandomSex($object, .8); |
120
|
1 |
|
$this->setRandomGenderIdentity($object, .8); |
121
|
1 |
|
$this->setRandomAnniversary($object, .4); |
122
|
|
|
|
123
|
1 |
|
return $object; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Initialize granular geo data |
128
|
|
|
* |
129
|
|
|
* @param ObjectInterface $object Object |
130
|
|
|
*/ |
131
|
1 |
|
protected function initializeLatitudeLongitudeAltitude(ObjectInterface $object) |
132
|
|
|
{ |
133
|
1 |
|
if ($this->happens(.8)) { |
134
|
1 |
|
$this->setLatitude($object); // p-latitude - decimal latitude |
135
|
1 |
|
$this->setLongitude($object); // p-longitude - decimal longitude |
136
|
1 |
|
$this->setRandomAltitude($object, .5); // p-altitude - decimal altitude |
137
|
|
|
} |
138
|
1 |
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Mutate the article |
142
|
|
|
* |
143
|
|
|
* @param ObjectInterface $object Contact |
144
|
|
|
* @return ObjectInterface Contact |
145
|
|
|
*/ |
146
|
1 |
|
public function mutate(ObjectInterface $object) |
147
|
|
|
{ |
148
|
1 |
|
$object->setPayload(Random::markdown()); // e-content |
149
|
|
|
|
150
|
1 |
|
$this->setRandomTitle($object, .1); |
151
|
1 |
|
$this->setRandomDescription($object, .2); // p-summary |
152
|
1 |
|
$this->setRandomAbstract($object, .1); |
153
|
1 |
|
$this->setRandomCategories($object, .2); // p-category |
154
|
1 |
|
$this->setRandomKeywords($object, .2); |
155
|
|
|
// $this->setAuthors($object); // TODO p-author |
156
|
|
|
|
157
|
1 |
|
return $object; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Set the contact email |
162
|
|
|
* |
163
|
|
|
* @param ObjectInterface $object Contact |
164
|
|
|
* @return ObjectInterface $object Contact |
165
|
|
|
*/ |
166
|
1 |
|
protected function setEmail(ObjectInterface $object) |
167
|
|
|
{ |
168
|
|
|
/** @noinspection PhpUndefinedMethodInspection */ |
169
|
1 |
|
return $object->setDomainProperty(ContactProperties::EMAIL, $this->generator->email()); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Set a logo |
174
|
|
|
* |
175
|
|
|
* @param ObjectInterface $object Contact |
176
|
|
|
* @return ObjectInterface $object Contact |
177
|
|
|
*/ |
178
|
|
|
protected function setLogo(ObjectInterface $object) |
179
|
|
|
{ |
180
|
|
|
return $object->setDomainProperty(ContactProperties::LOGO, $this->generator->imageUrl()); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Set a photo |
185
|
|
|
* |
186
|
|
|
* @param ObjectInterface $object Contact |
187
|
|
|
* @return ObjectInterface $object Contact |
188
|
|
|
*/ |
189
|
1 |
|
protected function setPhoto(ObjectInterface $object) |
190
|
|
|
{ |
191
|
1 |
|
return $object->setDomainProperty(ContactProperties::PHOTO, $this->generator->imageUrl()); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Set a URL |
196
|
|
|
* |
197
|
|
|
* @param ObjectInterface $object Contact |
198
|
|
|
* @return ObjectInterface $object Contact |
199
|
|
|
*/ |
200
|
1 |
|
protected function setUrl(ObjectInterface $object) |
201
|
|
|
{ |
202
|
|
|
/** @noinspection PhpUndefinedMethodInspection */ |
203
|
1 |
|
return $object->setDomainProperty(ContactProperties::URL, $this->generator->url()); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Set a telephone number |
208
|
|
|
* |
209
|
|
|
* @param ObjectInterface $object Contact |
210
|
|
|
* @return ObjectInterface $object Contact |
211
|
|
|
*/ |
212
|
|
|
protected function setTel(ObjectInterface $object) |
213
|
|
|
{ |
214
|
|
|
return $object->setDomainProperty(ContactProperties::TEL, '+'.$this->generator->randomNumber(8)); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Set an additional note |
219
|
|
|
* |
220
|
|
|
* @param ObjectInterface $object Contact |
221
|
|
|
* @return ObjectInterface $object Contact |
222
|
|
|
*/ |
223
|
|
|
protected function setNote(ObjectInterface $object) |
224
|
|
|
{ |
225
|
|
|
return $object->setDomainProperty(ContactProperties::NOTE, $this->generator->text()); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Set a birthday |
230
|
|
|
* |
231
|
|
|
* @param ObjectInterface $object Contact |
232
|
|
|
* @return ObjectInterface $object Contact |
233
|
|
|
*/ |
234
|
1 |
|
protected function setBday(ObjectInterface $object) |
235
|
|
|
{ |
236
|
1 |
|
return $object->setDomainProperty(ContactProperties::BDAY, $this->generator->dateTime->format('c')); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Set a cryptographic key |
241
|
|
|
* |
242
|
|
|
* @param ObjectInterface $object Contact |
243
|
|
|
* @return ObjectInterface $object Contact |
244
|
|
|
*/ |
245
|
|
|
protected function setKey(ObjectInterface $object) |
246
|
|
|
{ |
247
|
|
|
return $object->setDomainProperty( |
248
|
|
|
ContactProperties::KEY, |
249
|
|
|
'0x'.substr($this->generator->creditCardNumber, 0, 8) |
250
|
|
|
); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Set a birthday |
255
|
|
|
* |
256
|
|
|
* @param ObjectInterface $object Contact |
257
|
|
|
* @return ObjectInterface $object Contact |
258
|
|
|
*/ |
259
|
1 |
|
protected function setOrg(ObjectInterface $object) |
260
|
|
|
{ |
261
|
1 |
|
if ($this->happens(.5)) { |
262
|
1 |
|
return $object->setDomainProperty(ContactProperties::ORG, Random::apparatUrl(Object::CONTACT)); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
return $object->setDomainProperty(ContactProperties::ORG, $this->generator->company); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Set a job title |
270
|
|
|
* |
271
|
|
|
* @param ObjectInterface $object Contact |
272
|
|
|
* @return ObjectInterface $object Contact |
273
|
|
|
*/ |
274
|
1 |
|
protected function setJobTitle(ObjectInterface $object) |
275
|
|
|
{ |
276
|
1 |
|
return $object->setDomainProperty(ContactProperties::JOB_TITLE, $this->generator->jobTitle); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Set a role |
281
|
|
|
* |
282
|
|
|
* @param ObjectInterface $object Contact |
283
|
|
|
* @return ObjectInterface $object Contact |
284
|
|
|
*/ |
285
|
|
|
protected function setRole(ObjectInterface $object) |
286
|
|
|
{ |
287
|
|
|
return $object->setDomainProperty(ContactProperties::ROLE, $this->generator->jobTitle); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Set an instant messager profiel |
292
|
|
|
* |
293
|
|
|
* @param ObjectInterface $object Contact |
294
|
|
|
* @return ObjectInterface $object Contact |
295
|
|
|
*/ |
296
|
|
|
protected function setImpp(ObjectInterface $object) |
297
|
|
|
{ |
298
|
|
|
$type = $this->generator->randomElement([ |
|
|
|
|
299
|
|
|
'sip', |
300
|
|
|
'xmpp', |
301
|
|
|
'irc', |
302
|
|
|
'ymsgr', |
303
|
|
|
'msn', |
304
|
|
|
'aim', |
305
|
|
|
'im', |
306
|
|
|
'pres' |
307
|
|
|
]); |
308
|
|
|
return $object->setDomainProperty(ContactProperties::IMPP, $type.':'.$this->generator->userName); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Set a role |
313
|
|
|
* |
314
|
|
|
* @param ObjectInterface $object Contact |
315
|
|
|
* @return ObjectInterface $object Contact |
316
|
|
|
*/ |
317
|
|
|
protected function setSex(ObjectInterface $object) |
318
|
|
|
{ |
319
|
|
|
return $object->setDomainProperty( |
320
|
|
|
ContactProperties::SEX, |
321
|
|
|
$this->generator->randomElement(['M', 'F', 'O', 'N', 'U']) |
|
|
|
|
322
|
|
|
); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* Set a gender identity |
327
|
|
|
* |
328
|
|
|
* @param ObjectInterface $object Contact |
329
|
|
|
* @return ObjectInterface $object Contact |
330
|
|
|
*/ |
331
|
1 |
|
protected function setGenderIdentity(ObjectInterface $object) |
332
|
|
|
{ |
333
|
1 |
|
return $object->setDomainProperty(ContactProperties::GENDER_IDENTITY, $this->generator->words(3, true)); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Set a anniversary |
338
|
|
|
* |
339
|
|
|
* @param ObjectInterface $object Contact |
340
|
|
|
* @return ObjectInterface $object Contact |
341
|
|
|
*/ |
342
|
1 |
|
protected function setAnniversary(ObjectInterface $object) |
343
|
|
|
{ |
344
|
1 |
|
return $object->setDomainProperty(ContactProperties::ANNIVERSARY, $this->generator->dateTime->format('Y-m-d')); |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|