Skip to content

Commit a124292

Browse files
Spamercz
authored andcommitted
💥
WIP
1 parent 355b7f8 commit a124292

29 files changed

+1172
-21
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\ElasticQuery\Aggregation;
4+
5+
6+
abstract class AbstractLeafAggregation extends \Spameri\ElasticQuery\Entity\AbstractEntity
7+
{
8+
9+
abstract public function name() : string ;
10+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\ElasticQuery\Aggregation;
4+
5+
6+
class AggregationCollection extends AbstractLeafAggregation
7+
{
8+
9+
/**
10+
* @var string
11+
*/
12+
private $name;
13+
/**
14+
* @var \Spameri\ElasticQuery\Filter\FilterCollection
15+
*/
16+
private $filter;
17+
/**
18+
* @var \Spameri\ElasticQuery\Aggregation\AbstractLeafAggregation
19+
*/
20+
private $aggregations;
21+
22+
23+
public function __construct(
24+
string $name,
25+
?\Spameri\ElasticQuery\Filter\FilterCollection $filter,
26+
\Spameri\ElasticQuery\Aggregation\AbstractLeafAggregation ... $aggregations
27+
)
28+
{
29+
if ( ! $filter) {
30+
$filter = new \Spameri\ElasticQuery\Filter\FilterCollection();
31+
}
32+
33+
$this->name = $name;
34+
$this->filter = $filter;
35+
$this->aggregations = $aggregations;
36+
}
37+
38+
39+
public function name() : string
40+
{
41+
return $this->name;
42+
}
43+
44+
45+
public function key() : string
46+
{
47+
return $this->name;
48+
}
49+
50+
51+
public function toArray() : array
52+
{
53+
$array['aggregations'][$this->name] = [];
54+
55+
if ($this->filter) {
56+
$array['aggregations'][$this->name] = $this->filter->toArray();
57+
}
58+
59+
foreach ($this->aggregations as $aggregation) {
60+
$array['aggregations'][$this->name]['aggregations'][$aggregation->name()] = $aggregation->toArray();
61+
}
62+
63+
return $array;
64+
}
65+
66+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\ElasticQuery\Collection;
4+
5+
6+
abstract class AbstractCollection implements CollectionInterface
7+
{
8+
9+
/**
10+
* @var \Spameri\ElasticQuery\Entity\AbstractEntity[]
11+
*/
12+
private $collection;
13+
14+
15+
public function __construct(
16+
\Spameri\ElasticQuery\Entity\AbstractEntity ... $collection
17+
)
18+
{
19+
$this->collection = $collection;
20+
}
21+
22+
23+
public function add(
24+
\Spameri\ElasticQuery\Entity\AbstractEntity $item
25+
) : void
26+
{
27+
$this->collection[$item->key()] = $item;
28+
}
29+
30+
31+
public function remove(
32+
string $key
33+
) : bool
34+
{
35+
if (isset($this->collection[$key])) {
36+
unset($this->collection[$key]);
37+
38+
return TRUE;
39+
}
40+
41+
return FALSE;
42+
}
43+
44+
45+
public function get(
46+
string $key
47+
) : ?\Spameri\ElasticQuery\Entity\AbstractEntity
48+
{
49+
if (isset($this->collection[$key])) {
50+
return $this->collection[$key];
51+
}
52+
53+
return NULL;
54+
}
55+
56+
57+
public function isValue(
58+
string $key
59+
) : bool
60+
{
61+
if (isset($this->collection[$key])) {
62+
return TRUE;
63+
}
64+
65+
return FALSE;
66+
}
67+
68+
69+
public function count() : int
70+
{
71+
return \count($this->collection);
72+
}
73+
74+
75+
public function keys() : array
76+
{
77+
return \array_map('\strval', \array_keys($this->collection));
78+
}
79+
80+
81+
public function clear() : void
82+
{
83+
$this->collection = [];
84+
}
85+
86+
87+
public function getIterator() : \ArrayIterator
88+
{
89+
return new \ArrayIterator($this->collection);
90+
}
91+
92+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php declare(strict_types = 1);
2+
3+
4+
namespace Spameri\ElasticQuery\Collection;
5+
6+
7+
interface CollectionInterface extends \IteratorAggregate
8+
{
9+
10+
// public function add(
11+
// \Spameri\ElasticQuery\Entity\EntityInterface $item
12+
// ) : void;
13+
14+
15+
public function remove(
16+
string $key
17+
) : bool;
18+
19+
20+
// public function get(
21+
// string $key
22+
// ) : ?\Spameri\ElasticQuery\Entity\AbstractEntity;
23+
24+
25+
public function isValue(
26+
string $key
27+
) : bool;
28+
29+
30+
public function count() : int;
31+
32+
33+
public function keys() : array;
34+
35+
36+
public function clear() : void;
37+
38+
}

src/ElasticQuery.php

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,61 @@
1-
<?php declare(strict_types = 1);
2-
3-
namespace Spameri\ElasticQuery;
4-
5-
6-
class Query
7-
{
8-
9-
public function __construct(
10-
11-
)
12-
{
13-
14-
}
15-
16-
17-
public function toArray() : array
18-
{
19-
return [];
20-
}
21-
}
1+
<?php declare(strict_types=1);
2+
3+
namespace Spameri\ElasticQuery;
4+
5+
6+
class ElasticQuery implements \Spameri\ElasticQuery\Entity\ArrayInterface
7+
{
8+
9+
/**
10+
* @var \Spameri\ElasticQuery\Query\QueryCollection
11+
*/
12+
private $query;
13+
/**
14+
* @var \Spameri\ElasticQuery\Filter\FilterCollection
15+
*/
16+
private $filter;
17+
18+
19+
public function __construct(
20+
?\Spameri\ElasticQuery\Query\QueryCollection $query
21+
, ?\Spameri\ElasticQuery\Filter\FilterCollection $filter
22+
, $aggregation
23+
)
24+
{
25+
if ( ! $query) {
26+
$query = new \Spameri\ElasticQuery\Query\QueryCollection();
27+
}
28+
29+
if ( ! $filter) {
30+
$filter = new \Spameri\ElasticQuery\Filter\FilterCollection();
31+
}
32+
33+
$this->query = $query;
34+
$this->filter = $filter;
35+
}
36+
37+
38+
public function query() : \Spameri\ElasticQuery\Query\QueryCollection
39+
{
40+
return $this->query;
41+
}
42+
43+
44+
public function filter() : \Spameri\ElasticQuery\Filter\FilterCollection
45+
{
46+
return $this->filter;
47+
}
48+
49+
50+
public function toArray() : array
51+
{
52+
$array = [
53+
'query' => $this->query->toArray(),
54+
'filter' => $this->filter->toArray(),
55+
'sort',
56+
'aggregation',
57+
];
58+
59+
return $array;
60+
}
61+
}

src/Entity/AbstractEntity.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\Entity;
4+
5+
6+
abstract class AbstractEntity implements EntityInterface
7+
{
8+
9+
}

src/Entity/ArrayInterface.php

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

src/Entity/EntityInterface.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\ElasticQuery\Entity;
4+
5+
6+
interface EntityInterface extends ArrayInterface
7+
{
8+
9+
public function key() : string;
10+
11+
}
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\Exception;
4+
5+
6+
class InvalidArgumentException extends \InvalidArgumentException
7+
{
8+
9+
}

src/Filter/AbstractLeafFilter.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\Filter;
4+
5+
6+
abstract class AbstractLeafFilter implements FilterInterface
7+
{
8+
9+
}

0 commit comments

Comments
 (0)