|
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\Factory; |
|
38
|
|
|
|
|
39
|
|
|
use Apparat\Dev\Infrastructure\Mutator\ArticleObjectMutator; |
|
40
|
|
|
use Apparat\Dev\Infrastructure\Mutator\ContactObjectMutator; |
|
41
|
|
|
use Apparat\Dev\Infrastructure\Mutator\ObjectMutatorInterface; |
|
42
|
|
|
use Apparat\Dev\Ports\Repository; |
|
43
|
|
|
use Apparat\Kernel\Ports\Kernel; |
|
44
|
|
|
use Apparat\Object\Domain\Model\Object\ObjectInterface; |
|
45
|
|
|
use Apparat\Object\Ports\Types\Object; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Object factory |
|
49
|
|
|
* |
|
50
|
|
|
* @package Apparat\Dev |
|
51
|
|
|
* @subpackage Apparat\Dev\Infrastructure |
|
52
|
|
|
*/ |
|
53
|
|
|
class ObjectFactory extends AbstractObjectFactory |
|
54
|
|
|
{ |
|
55
|
|
|
/** |
|
56
|
|
|
* Create a repository object |
|
57
|
|
|
* |
|
58
|
|
|
* @param \DateTimeInterface $creationDate Creation date |
|
59
|
|
|
* @param int $objectId Object ID |
|
60
|
|
|
* @param array $config Object configuration |
|
61
|
|
|
*/ |
|
62
|
2 |
|
public function create(\DateTimeInterface $creationDate, $objectId, array $config) |
|
63
|
|
|
{ |
|
64
|
2 |
|
$objectTypeMethod = ucfirst($config[Repository::TYPE]); |
|
65
|
2 |
|
$objectMutator = null; |
|
66
|
|
|
|
|
67
|
|
|
/** @var ObjectInterface $object */ |
|
68
|
2 |
|
$object = $this->{'create'.$objectTypeMethod}($creationDate, $objectMutator); |
|
69
|
|
|
|
|
70
|
|
|
// Create the object revisions |
|
71
|
2 |
|
$this->createObjectRevisions($object, $config, $objectMutator); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
// Eventually hide the object if necessary |
|
74
|
2 |
|
if (($config[Repository::HIDDEN] > 0) ? (rand(min(0, $objectId), 100) < ($config[Repository::HIDDEN] * 100)) |
|
75
|
2 |
|
: false) { |
|
76
|
2 |
|
$object->delete()->persist(); |
|
77
|
|
|
} |
|
78
|
2 |
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Create the object revisions |
|
82
|
|
|
* |
|
83
|
|
|
* @param ObjectInterface $object Object |
|
84
|
|
|
* @param array $config Object configuration |
|
85
|
|
|
* @param ObjectMutatorInterface $objectMutator Object mutator |
|
86
|
|
|
*/ |
|
87
|
2 |
|
protected function createObjectRevisions( |
|
88
|
|
|
ObjectInterface $object, |
|
89
|
|
|
array $config, |
|
90
|
|
|
ObjectMutatorInterface $objectMutator |
|
91
|
|
|
) { |
|
92
|
|
|
// Determine the amount of archive revisions to create |
|
93
|
2 |
|
$revisions = ($config[Repository::REVISIONS] < 0) ? |
|
94
|
2 |
|
rand(1, abs($config[Repository::REVISIONS]) + 1) : (1 + $config[Repository::REVISIONS]); |
|
95
|
|
|
|
|
96
|
|
|
// Determine the draft status |
|
97
|
2 |
|
$draft = (($config[Repository::DRAFTS] > 0) ? (rand(0, 100) < $config[Repository::DRAFTS] * 100) : 0); |
|
98
|
|
|
|
|
99
|
|
|
// Build the revision path list |
|
100
|
2 |
|
for ($revision = 1; $revision < $revisions - $draft; ++$revision) { |
|
101
|
2 |
|
$objectMutator->mutate($object)->publish()->persist(); |
|
102
|
|
|
} |
|
103
|
2 |
|
if ($revision <= $revisions - $draft) { |
|
104
|
2 |
|
$objectMutator->mutate($object)->publish()->persist(); |
|
105
|
|
|
} |
|
106
|
2 |
|
if ($draft) { |
|
107
|
2 |
|
$objectMutator->mutate($object)->persist(); |
|
108
|
|
|
} |
|
109
|
2 |
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Create an article object |
|
113
|
|
|
* |
|
114
|
|
|
* @param \DateTimeInterface $creationDate Creation date |
|
115
|
|
|
* @return ObjectInterface Article |
|
116
|
|
|
*/ |
|
117
|
1 |
|
protected function createArticle(\DateTimeInterface $creationDate, ObjectMutatorInterface &$objectMutator = null) |
|
118
|
|
|
{ |
|
119
|
|
|
/** @var ObjectMutatorInterface $objectMutator */ |
|
120
|
1 |
|
$objectMutator = Kernel::create(ArticleObjectMutator::class); |
|
121
|
1 |
|
return $objectMutator->initialize($this->repository->createObject(Object::ARTICLE, '', [], $creationDate)); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Create a contact object |
|
126
|
|
|
* |
|
127
|
|
|
* @param \DateTimeInterface $creationDate Creation date |
|
128
|
|
|
* @return ObjectInterface Contact |
|
129
|
|
|
*/ |
|
130
|
1 |
|
protected function createContact(\DateTimeInterface $creationDate, ObjectMutatorInterface &$objectMutator = null) |
|
131
|
|
|
{ |
|
132
|
|
|
/** @var ObjectMutatorInterface $objectMutator */ |
|
133
|
1 |
|
$objectMutator = Kernel::create(ContactObjectMutator::class); |
|
134
|
1 |
|
return $objectMutator->initialize($this->repository->createObject(Object::CONTACT, '', [], $creationDate)); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: