1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Elastification\Client\Repository; |
20
|
|
|
|
21
|
|
|
use Elastification\Client\ClientInterface; |
22
|
|
|
use Elastification\Client\ClientVersionMapInterface; |
23
|
|
|
use Elastification\Client\Request\RequestInterface; |
24
|
|
|
use Elastification\Client\Serializer\SerializerInterface; |
25
|
|
|
|
26
|
|
|
abstract class AbstractRepository |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ClientInterface |
31
|
|
|
*/ |
32
|
|
|
protected $client; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var SerializerInterface |
36
|
|
|
*/ |
37
|
|
|
private $serializer; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $versionFolder; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var RepositoryClassMap |
46
|
|
|
*/ |
47
|
|
|
protected $repositoryClassMap; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var RequestRepositoryFactoryInterface |
51
|
|
|
*/ |
52
|
|
|
private $requestRepositoryFactory; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param ClientInterface $client |
56
|
|
|
* @param SerializerInterface $serializer |
57
|
|
|
* @param RepositoryClassMapInterface $repositoryClassMap |
58
|
|
|
* @param string $versionFolder |
59
|
|
|
* @param RequestRepositoryFactoryInterface $requestRepositoryFactory |
60
|
|
|
*/ |
61
|
42 |
|
public function __construct( |
62
|
|
|
ClientInterface $client, |
63
|
|
|
SerializerInterface $serializer, |
64
|
|
|
RepositoryClassMapInterface $repositoryClassMap = null, |
65
|
|
|
$versionFolder = ClientVersionMapInterface::VERSION_V1X, |
66
|
|
|
RequestRepositoryFactoryInterface $requestRepositoryFactory = null |
67
|
|
|
) { |
68
|
42 |
|
$this->client = $client; |
69
|
42 |
|
$this->serializer = $serializer; |
70
|
42 |
|
$this->versionFolder = (string)$versionFolder; |
71
|
|
|
|
72
|
42 |
|
if (null === $repositoryClassMap) { |
73
|
4 |
|
$this->repositoryClassMap = new RepositoryClassMap($versionFolder); |
74
|
4 |
|
} else { |
75
|
42 |
|
$this->repositoryClassMap = $repositoryClassMap; |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
42 |
|
if (null === $requestRepositoryFactory) { |
79
|
4 |
|
$this->requestRepositoryFactory = new RequestRepositoryFactory(); |
80
|
4 |
|
} else { |
81
|
42 |
|
$this->requestRepositoryFactory = $requestRepositoryFactory; |
82
|
|
|
} |
83
|
42 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* creates an request instance |
87
|
|
|
* |
88
|
|
|
* @param string $requestName |
89
|
|
|
* @param string $index |
90
|
|
|
* @param string $type |
91
|
|
|
* |
92
|
|
|
* @return RequestInterface |
93
|
|
|
* @author Daniel Wendlandt |
94
|
|
|
*/ |
95
|
33 |
|
protected function createRequestInstance($requestName, $index, $type) |
96
|
|
|
{ |
97
|
33 |
|
$class = $this->getClass($requestName); |
98
|
|
|
|
99
|
|
|
/** @var RequestInterface $request */ |
100
|
|
|
|
101
|
32 |
|
return $this->requestRepositoryFactory->create($class, $index, $type, $this->serializer); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* gets the right class string of a version |
106
|
|
|
* |
107
|
|
|
* @param string $class |
108
|
|
|
* |
109
|
|
|
* @return string |
110
|
|
|
* @author Daniel Wendlandt |
111
|
|
|
*/ |
112
|
32 |
|
protected function getClass($class) |
113
|
|
|
{ |
114
|
32 |
|
return $this->repositoryClassMap->getClassName($class); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.