Skip to content

Commit 4c5dc35

Browse files
committed
💥
WIP
1 parent a124292 commit 4c5dc35

File tree

4 files changed

+111
-14
lines changed

4 files changed

+111
-14
lines changed

src/Body.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Document.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\ElasticQuery;
4+
5+
6+
class Document implements \Spameri\ElasticQuery\Entity\ArrayInterface
7+
{
8+
9+
/**
10+
* @var ?string
11+
*/
12+
private $index;
13+
/**
14+
* @var ?\Spameri\ElasticQuery\Document\BodyInterface
15+
*/
16+
private $body;
17+
/**
18+
* @var ?string
19+
*/
20+
private $type;
21+
/**
22+
* @var ?string
23+
*/
24+
private $id;
25+
/**
26+
* @var array
27+
*/
28+
private $options;
29+
30+
31+
public function __construct(
32+
?string $index
33+
, ?\Spameri\ElasticQuery\Document\BodyInterface $body = NULL
34+
, ?string $type = NULL
35+
, ?string $id = NULL
36+
, array $options = []
37+
)
38+
{
39+
$this->index = $index;
40+
$this->body = $body;
41+
$this->type = $type;
42+
$this->id = $id;
43+
$this->options = $options;
44+
}
45+
46+
47+
public function toArray() : array
48+
{
49+
$array = [];
50+
51+
if ($this->index) {
52+
$array['index'] = $this->index;
53+
}
54+
55+
if ($this->body) {
56+
$array['body'] = $this->body->toArray();
57+
}
58+
59+
if ($this->type) {
60+
$array['type'] = $this->type;
61+
}
62+
63+
if ($this->id) {
64+
$array['id'] = $this->id;
65+
}
66+
67+
if ($this->options) {
68+
$array = \array_merge($array, $this->options);
69+
}
70+
71+
return $array;
72+
}
73+
74+
}

src/Document/Body/Plain.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\ElasticQuery\Document\Body;
4+
5+
6+
class Plain implements \Spameri\ElasticQuery\Document\BodyInterface
7+
{
8+
9+
/**
10+
* @var array
11+
*/
12+
private $parameters;
13+
14+
15+
public function __construct(
16+
array $parameters
17+
)
18+
{
19+
$this->parameters = $parameters;
20+
}
21+
22+
23+
public function toArray() : array
24+
{
25+
return $this->parameters;
26+
}
27+
28+
}

src/Document/BodyInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\ElasticQuery\Document;
4+
5+
6+
interface BodyInterface extends \Spameri\ElasticQuery\Entity\ArrayInterface
7+
{
8+
9+
}

0 commit comments

Comments
 (0)