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
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Contact object mutator |
47
|
|
|
* |
48
|
|
|
* @package Apparat\Dev |
49
|
|
|
* @subpackage Apparat\Dev\Infrastructure |
50
|
|
|
* @method ObjectInterface setRandomEmail(ObjectInterface $object, $probability) |
51
|
|
|
* @method ObjectInterface setRandomLogo(ObjectInterface $object, $probability) |
52
|
|
|
* @method ObjectInterface setRandomPhoto(ObjectInterface $object, $probability) |
53
|
|
|
* @method ObjectInterface setRandomUrl(ObjectInterface $object, $probability) |
54
|
|
|
* |
55
|
|
|
|
56
|
|
|
*/ |
57
|
|
|
class ContactObjectMutator extends AbstractObjectMutator |
58
|
|
|
{ |
59
|
|
|
/** |
60
|
|
|
* Use traits |
61
|
|
|
*/ |
62
|
|
|
use NameMutatorTrait, AddressMutatorTrait; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Initialize the contact |
66
|
|
|
* |
67
|
|
|
* @param ObjectInterface $object Contact |
68
|
|
|
* @return ObjectInterface Contact |
69
|
|
|
*/ |
70
|
1 |
|
public function initialize(ObjectInterface $object) |
71
|
|
|
{ |
72
|
1 |
|
$this->setRandomLocation($object, .6); // p-location |
73
|
1 |
|
$this->setRandomDescription($object, .2); // p-summary |
74
|
1 |
|
$this->setRandomCategories($object, .4); // p-category |
75
|
1 |
|
$this->setRandomKeywords($object, .7); |
76
|
1 |
|
$this->setAuthors($object); |
77
|
|
|
|
78
|
|
|
// p-name - full/formatted name of the person or organisation (automatically set via the various name facets) |
79
|
1 |
|
$this->setRandomHonorificPrefix($object, .3); // p-honorific-prefix - e.g. Mrs., Mr. or Dr. |
80
|
1 |
|
$this->setGivenName($object); // p-given-name - given (often first) name |
81
|
1 |
|
$this->setRandomNickname($object, .3); // p-nickname - nickname/alias/handle |
82
|
1 |
|
$this->setRandomAdditionalName($object, .2); // p-additional-name - other/middle name |
83
|
1 |
|
$this->setRandomFamilyName($object, .9);// p-family-name - family (often last) name |
84
|
1 |
|
$this->setRandomHonorificSuffix($object, .1); // p-honorific-suffix - e.g. Ph.D, Esq. |
85
|
1 |
|
$this->setSortString($object); // p-sort-string - string to sort by |
86
|
|
|
|
87
|
1 |
|
$this->setRandomEmail($object, .5); // u-email - email address |
88
|
1 |
|
$this->setRandomLogo($object, .2); // u-logo - a logo representing the person or organisation |
89
|
1 |
|
$this->setRandomPhoto($object, .4); // u-photo |
90
|
1 |
|
$this->setRandomUrl($object, .7); // u-url - home page |
91
|
|
|
|
92
|
|
|
// Initialize a postal address |
93
|
1 |
|
$this->happens(.4) ? |
94
|
1 |
|
$this->setRandomAdr($object, .8) : // p-adr - postal address, optionally embed an h-adr |
95
|
1 |
|
$this->initializeAddress($object); |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
// p-geo or u-geo, optionally embed an h-geo |
99
|
|
|
// Main article: h-geo |
100
|
|
|
// p-latitude - decimal latitude |
101
|
|
|
// p-longitude - decimal longitude |
102
|
|
|
// p-altitude - decimal altitude |
103
|
|
|
// p-tel - telephone number |
104
|
|
|
// p-note - additional notes |
105
|
|
|
// dt-bday - birth date |
106
|
|
|
// u-key - cryptographic public key e.g. SSH or GPG |
107
|
|
|
// p-org - affiliated organization, optionally embed an h-card |
108
|
|
|
// p-job-title - job title, previously 'title' in hCard, disambiguated. |
109
|
|
|
// p-role - description of role |
110
|
|
|
// u-impp per RFC4770, new in vCard4 (RFC 6350) |
111
|
|
|
// p-sex - biological sex, new in vCard4 (RFC 6350) |
112
|
|
|
// p-gender-identity - gender identity, new in vCard4 (RFC 6350) |
113
|
|
|
// dt-anniversary |
114
|
|
|
|
115
|
1 |
|
return $object; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Mutate the article |
121
|
|
|
* |
122
|
|
|
* @param ObjectInterface $object Contact |
123
|
|
|
* @return ObjectInterface Contact |
124
|
|
|
*/ |
125
|
1 |
|
public function mutate(ObjectInterface $object) |
126
|
|
|
{ |
127
|
1 |
|
$object->setPayload(Random::markdown()); // e-content |
128
|
|
|
|
129
|
1 |
|
$this->setRandomTitle($object, .1); |
130
|
1 |
|
$this->setRandomDescription($object, .2); // p-summary |
131
|
1 |
|
$this->setRandomAbstract($object, .1); |
132
|
1 |
|
$this->setRandomCategories($object, .2); // p-category |
133
|
1 |
|
$this->setRandomKeywords($object, .2); |
134
|
|
|
// $this->setAuthors($object); // TODO p-author |
135
|
|
|
|
136
|
1 |
|
return $object; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Set the contact email |
142
|
|
|
* |
143
|
|
|
* @param ObjectInterface $object Contact |
144
|
|
|
* @return ObjectInterface $object Contact |
145
|
|
|
*/ |
146
|
1 |
|
protected function setEmail(ObjectInterface $object) |
147
|
|
|
{ |
148
|
|
|
/** @noinspection PhpUndefinedMethodInspection */ |
149
|
1 |
|
return $object->setDomainProperty(ContactProperties::EMAIL, $this->generator->email()); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Set a logo |
154
|
|
|
* |
155
|
|
|
* @param ObjectInterface $object Contact |
156
|
|
|
* @return ObjectInterface $object Contact |
157
|
|
|
*/ |
158
|
1 |
|
protected function setLogo(ObjectInterface $object) |
159
|
|
|
{ |
160
|
1 |
|
return $object->setDomainProperty(ContactProperties::LOGO, $this->generator->imageUrl()); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Set a photo |
165
|
|
|
* |
166
|
|
|
* @param ObjectInterface $object Contact |
167
|
|
|
* @return ObjectInterface $object Contact |
168
|
|
|
*/ |
169
|
1 |
|
protected function setPhoto(ObjectInterface $object) |
170
|
|
|
{ |
171
|
1 |
|
return $object->setDomainProperty(ContactProperties::PHOTO, $this->generator->imageUrl()); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Set a URL |
176
|
|
|
* |
177
|
|
|
* @param ObjectInterface $object Contact |
178
|
|
|
* @return ObjectInterface $object Contact |
179
|
|
|
*/ |
180
|
1 |
|
protected function setUrl(ObjectInterface $object) |
181
|
|
|
{ |
182
|
|
|
/** @noinspection PhpUndefinedMethodInspection */ |
183
|
1 |
|
return $object->setDomainProperty(ContactProperties::URL, $this->generator->url()); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|