|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
* @author [email protected] |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Core\Service; |
|
12
|
|
|
|
|
13
|
|
|
use Core\Entity\EntityInterface; |
|
14
|
|
|
use Core\Entity\Hydrator\CloneHydrator; |
|
15
|
|
|
use Core\Entity\Hydrator\EntityHydrator; |
|
16
|
|
|
use Core\Entity\SnapshotInterface; |
|
17
|
|
|
use Core\Entity\SnapshotMeta; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class SnapshotGenerator |
|
21
|
|
|
* @package Core\Service |
|
22
|
|
|
*/ |
|
23
|
|
|
class SnapshotGenerator |
|
24
|
|
|
{ |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $hydrator; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* |
|
33
|
|
|
* |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $snapshotAttributes = []; |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param $hydrator |
|
41
|
|
|
* @return $this |
|
42
|
|
|
*/ |
|
43
|
|
|
public function setHydrator($hydrator) |
|
44
|
|
|
{ |
|
45
|
|
|
if ($hydrator instanceof EntityHydrator) { |
|
46
|
|
|
$this->hydrator = $hydrator; |
|
47
|
|
|
} |
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return EntityHydrator |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getHydrator() |
|
55
|
|
|
{ |
|
56
|
|
|
if (!isset($this->hydrator)) { |
|
57
|
|
|
$this->hydrator = new CloneHydrator(); |
|
58
|
|
|
} |
|
59
|
|
|
return $this->hydrator; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param array $snapshotAttributes |
|
64
|
|
|
* |
|
65
|
|
|
* @return self |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setSnapshotAttributes($snapshotAttributes) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->snapshotAttributes = $snapshotAttributes; |
|
70
|
|
|
|
|
71
|
|
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return array |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getSnapshotAttributes() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->snapshotAttributes; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
public function __invoke($source, $attributes = [], $target = null) |
|
85
|
|
|
{ |
|
86
|
|
|
if (!is_array($attributes)) { |
|
87
|
|
|
$target = $attributes; |
|
88
|
|
|
$attributes = null; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (!$target) { |
|
92
|
|
|
$target = get_class($source) . 'Snapshot'; |
|
93
|
|
|
$target = new $target($source); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if ($target instanceOf SnapshotAttributesProviderInterface) { |
|
|
|
|
|
|
97
|
|
|
$attributes = $target->getSnapshotAttributes(); |
|
98
|
|
|
} else if (empty($attributes)) { |
|
99
|
|
|
$attributes = $this->getSnapshotAttributes(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$hydrator = $this->getHydrator(); |
|
103
|
|
|
$data = $hydrator->extract($source, $attributes); |
|
|
|
|
|
|
104
|
|
|
$snapshot = $hydrator->hydrate($target, $data); |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
return $snapshot; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.