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\Request\Shared; |
20
|
|
|
|
21
|
|
|
use Elastification\Client\Exception\RequestException; |
22
|
|
|
use Elastification\Client\Request\RequestMethods; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class AbstractUpdateDocumentRequest |
26
|
|
|
* |
27
|
|
|
* @package Elastification\Client\Request\Shared |
28
|
|
|
* @author Daniel Wendlandt |
29
|
|
|
*/ |
30
|
|
|
abstract class AbstractUpdateDocumentRequest extends AbstractBaseRequest |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var null|string |
34
|
|
|
*/ |
35
|
|
|
private $body = null; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var null|string |
39
|
|
|
*/ |
40
|
|
|
private $id = null; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritdoc |
44
|
|
|
*/ |
45
|
3 |
|
public function getMethod() |
46
|
|
|
{ |
47
|
3 |
|
return RequestMethods::PUT; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
*/ |
53
|
6 |
|
public function getAction() |
54
|
|
|
{ |
55
|
6 |
|
if (null === $this->id) { |
56
|
3 |
|
throw new RequestException('id can not be empty for this request'); |
57
|
|
|
} |
58
|
|
|
|
59
|
3 |
|
return $this->id; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritdoc |
64
|
|
|
*/ |
65
|
3 |
|
public function getBody() |
66
|
|
|
{ |
67
|
3 |
|
return $this->body; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @inheritdoc |
72
|
|
|
*/ |
73
|
6 |
|
public function setBody($body) |
74
|
|
|
{ |
75
|
6 |
|
if (empty($body)) { |
76
|
3 |
|
throw new RequestException('Body can not be empty'); |
77
|
|
|
} |
78
|
|
|
|
79
|
3 |
|
$this->body = $this->serializer->serialize($body, $this->serializerParams); |
80
|
3 |
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Sets the document id |
84
|
|
|
* |
85
|
|
|
* @param null|string $id |
86
|
|
|
* |
87
|
|
|
* @throws \Elastification\Client\Exception\RequestException |
88
|
|
|
* @author Daniel Wendlandt |
89
|
|
|
*/ |
90
|
6 |
|
public function setId($id) |
91
|
|
|
{ |
92
|
6 |
|
if (empty($id)) { |
93
|
3 |
|
throw new RequestException('Id can not be empty'); |
94
|
|
|
} |
95
|
|
|
|
96
|
3 |
|
$this->id = $id; |
97
|
3 |
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|