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
|
|
|
namespace Elastification\Client\Request\Shared; |
19
|
|
|
|
20
|
|
|
use Elastification\Client\Request\RequestInterface; |
21
|
|
|
use Elastification\Client\Serializer\JmsSerializer; |
22
|
|
|
use Elastification\Client\Serializer\SerializerInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class AbstractBaseRequest |
26
|
|
|
* |
27
|
|
|
* @package Elastification\Client\Request\Shared |
28
|
|
|
* @author Daniel Wendlandt |
29
|
|
|
*/ |
30
|
|
|
abstract class AbstractBaseRequest implements RequestInterface |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var \Elastification\Client\Serializer\SerializerInterface |
34
|
|
|
*/ |
35
|
|
|
protected $serializer; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $serializerParams = array(); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var null|string |
44
|
|
|
*/ |
45
|
|
|
protected $index = null; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var null|string |
49
|
|
|
*/ |
50
|
|
|
protected $type = null; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
protected $parameters = array(); |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $index |
59
|
|
|
* @param string $type |
60
|
|
|
* @param \Elastification\Client\Serializer\SerializerInterface $serializer |
61
|
|
|
* @param array $serializerParams |
62
|
|
|
* |
63
|
|
|
* @author Daniel Wendlandt |
64
|
|
|
*/ |
65
|
1473 |
|
public function __construct($index, $type, SerializerInterface $serializer, array $serializerParams = array()) |
66
|
|
|
{ |
67
|
1473 |
|
$this->serializer = $serializer; |
68
|
1473 |
|
if ($serializer instanceof JmsSerializer) { |
69
|
8 |
|
$this->serializerParams = array_merge(['index' => $index, 'type' => $type], $serializerParams); |
70
|
8 |
|
} else { |
71
|
1473 |
|
$this->serializerParams = $serializerParams; |
72
|
|
|
} |
73
|
|
|
|
74
|
1473 |
|
if (!empty($index)) { |
75
|
1115 |
|
$this->index = $index; |
76
|
1115 |
|
} |
77
|
|
|
|
78
|
1473 |
|
if (!empty($type)) { |
79
|
547 |
|
$this->type = $type; |
80
|
547 |
|
} |
81
|
1473 |
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @inheritdoc |
85
|
|
|
*/ |
86
|
90 |
|
public function getIndex() |
87
|
|
|
{ |
88
|
90 |
|
return $this->index; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @inheritdoc |
93
|
|
|
*/ |
94
|
79 |
|
public function getType() |
95
|
|
|
{ |
96
|
79 |
|
return $this->type; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @inheritdoc |
101
|
|
|
*/ |
102
|
157 |
|
public function getSerializer() |
103
|
|
|
{ |
104
|
157 |
|
return $this->serializer; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @inheritdoc |
109
|
|
|
*/ |
110
|
156 |
|
public function getSerializerParams() |
111
|
|
|
{ |
112
|
156 |
|
return $this->serializerParams; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Sets a parameter and casts value to string |
117
|
|
|
* |
118
|
|
|
* @param string $name |
119
|
|
|
* @param mixed $value |
120
|
|
|
* @author Daniel Wendlandt |
121
|
|
|
*/ |
122
|
330 |
|
public function setParameter($name, $value) |
123
|
|
|
{ |
124
|
330 |
|
$this->parameters[$name] = (string) $value; |
125
|
330 |
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Getter for parameters |
129
|
|
|
* |
130
|
|
|
* @return array |
131
|
|
|
* @author Daniel Wendlandt |
132
|
|
|
*/ |
133
|
40 |
|
public function getParameters() |
134
|
|
|
{ |
135
|
40 |
|
return $this->parameters; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|