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
|
|
|
*/ |
61
|
|
|
trait AddressMutatorTrait |
62
|
|
|
{ |
63
|
|
|
/** |
64
|
|
|
* Initialize a postal address |
65
|
|
|
* |
66
|
|
|
* @param ObjectInterface $object Object |
67
|
|
|
*/ |
68
|
1 |
|
protected function initializeAddress(ObjectInterface $object) |
69
|
|
|
{ |
70
|
1 |
|
$this->setRandomPostOfficeBox($object, .2); |
71
|
1 |
|
$this->setRandomExtendedAddress($object, .4); |
72
|
1 |
|
$this->setRandomStreetAddress($object, .9); |
73
|
1 |
|
$this->setLocality($object); |
74
|
1 |
|
$this->setRandomRegion($object, .5); |
75
|
1 |
|
$this->setRandomPostalCode($object, .9); |
76
|
1 |
|
$this->setRandomCountryName($object, .7); |
77
|
1 |
|
$this->setRandomLabel($object, .5); |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Set an embedded apparat address |
82
|
|
|
* |
83
|
|
|
* @param ObjectInterface $object Contact |
84
|
|
|
* @return ObjectInterface $object Contact |
85
|
|
|
*/ |
86
|
1 |
|
protected function setAdr(ObjectInterface $object) |
87
|
|
|
{ |
88
|
1 |
|
return $object->setDomainProperty(ContactProperties::ADR, Random::apparatUrl(Object::ADDRESS)); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Set the post office box |
93
|
|
|
* |
94
|
|
|
* @param ObjectInterface $object Contact |
95
|
|
|
* @return ObjectInterface $object Contact |
96
|
|
|
*/ |
97
|
|
|
protected function setPostOfficeBox(ObjectInterface $object) |
98
|
|
|
{ |
99
|
|
|
return $object->setDomainProperty(ContactProperties::POST_OFFICE_BOX, $this->generator->postcode); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Set the extended address |
104
|
|
|
* |
105
|
|
|
* @param ObjectInterface $object Contact |
106
|
|
|
* @return ObjectInterface $object Contact |
107
|
|
|
*/ |
108
|
1 |
|
protected function setExtendedAddress(ObjectInterface $object) |
109
|
|
|
{ |
110
|
1 |
|
return $object->setDomainProperty(ContactProperties::EXTENDED_ADDRESS, $this->generator->secondaryAddress); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Set the street address |
115
|
|
|
* |
116
|
|
|
* @param ObjectInterface $object Contact |
117
|
|
|
* @return ObjectInterface $object Contact |
118
|
|
|
*/ |
119
|
1 |
|
protected function setStreetAddress(ObjectInterface $object) |
120
|
|
|
{ |
121
|
1 |
|
return $object->setDomainProperty(ContactProperties::STREET_ADDRESS, $this->generator->streetAddress); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set the locality |
126
|
|
|
* |
127
|
|
|
* @param ObjectInterface $object Contact |
128
|
|
|
* @return ObjectInterface $object Contact |
129
|
|
|
*/ |
130
|
1 |
|
protected function setLocality(ObjectInterface $object) |
131
|
|
|
{ |
132
|
1 |
|
return $object->setDomainProperty(ContactProperties::LOCALITY, $this->generator->city); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Set the region |
137
|
|
|
* |
138
|
|
|
* @param ObjectInterface $object Contact |
139
|
|
|
* @return ObjectInterface $object Contact |
140
|
|
|
*/ |
141
|
1 |
|
protected function setRegion(ObjectInterface $object) |
142
|
|
|
{ |
143
|
1 |
|
return $object->setDomainProperty(ContactProperties::REGION, $this->generator->state); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Set the postal code |
148
|
|
|
* |
149
|
|
|
* @param ObjectInterface $object Contact |
150
|
|
|
* @return ObjectInterface $object Contact |
151
|
|
|
*/ |
152
|
1 |
|
protected function setPostalCode(ObjectInterface $object) |
153
|
|
|
{ |
154
|
1 |
|
return $object->setDomainProperty(ContactProperties::POSTAL_CODE, $this->generator->postcode); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Set the postal code |
159
|
|
|
* |
160
|
|
|
* @param ObjectInterface $object Contact |
161
|
|
|
* @return ObjectInterface $object Contact |
162
|
|
|
*/ |
163
|
1 |
|
protected function setCountryName(ObjectInterface $object) |
164
|
|
|
{ |
165
|
1 |
|
return $object->setDomainProperty(ContactProperties::COUNTRY_NAME, $this->generator->country); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Set the label |
170
|
|
|
* |
171
|
|
|
* @param ObjectInterface $object Contact |
172
|
|
|
* @return ObjectInterface $object Contact |
173
|
|
|
*/ |
174
|
1 |
|
protected function setLabel(ObjectInterface $object) |
175
|
|
|
{ |
176
|
1 |
|
return $object->setDomainProperty(ContactProperties::LABEL, $this->generator->address); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|