1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Donii Sergii <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace sonrac\Arango; |
7
|
|
|
|
8
|
|
|
use ArangoDBClient\Collection as ArangoCollection; |
9
|
|
|
use ArrayAccess; |
10
|
|
|
use Countable; |
11
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
12
|
|
|
use Illuminate\Contracts\Support\Jsonable; |
13
|
|
|
use Illuminate\Support\Collection as BaseCollection; |
14
|
|
|
use IteratorAggregate; |
15
|
|
|
use JsonSerializable; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Collection. |
19
|
|
|
* |
20
|
|
|
* @author Donii Sergii <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Collection extends BaseCollection implements ArrayAccess, Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Arango.DB Connection |
26
|
|
|
* |
27
|
|
|
* @var \sonrac\Arango\Connection |
28
|
|
|
* |
29
|
|
|
* @author Donii Sergii <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
protected $connection; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Arango.DB collection object |
35
|
|
|
* |
36
|
|
|
* @var \ArangoDBClient\Collection |
37
|
|
|
* |
38
|
|
|
* @author Donii Sergii <[email protected]> |
39
|
|
|
*/ |
40
|
|
|
protected $collection; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Items |
44
|
|
|
* |
45
|
|
|
* @var null|array |
46
|
|
|
* |
47
|
|
|
* @author Donii Sergii <[email protected]>4 |
48
|
|
|
*/ |
49
|
|
|
protected $items = null; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Collection constructor. |
53
|
|
|
* |
54
|
|
|
* @param \sonrac\Arango\Connection $connection Arango.DB connection |
55
|
|
|
* @param \ArangoDBClient\Collection $collection Arango.DB collection object |
56
|
|
|
* |
57
|
|
|
* @author Donii Sergii <[email protected]> |
58
|
|
|
*/ |
59
|
|
|
public function __construct(Connection $connection, ArangoCollection $collection) |
60
|
|
|
{ |
61
|
|
|
$this->connection = $connection; |
62
|
|
|
$this->collection = $collection; |
63
|
|
|
$this->items = $this->collection->getAll(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get element from collection |
68
|
|
|
* |
69
|
|
|
* @param string $name |
70
|
|
|
* |
71
|
|
|
* @return mixed |
72
|
|
|
* |
73
|
|
|
* @author Donii Sergii <[email protected]> |
74
|
|
|
*/ |
75
|
|
|
public function __get($name) |
76
|
|
|
{ |
77
|
|
|
if (isset($this->items[$name])) { |
78
|
|
|
return $this->items[$name]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return parent::__get($name); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Add to collection |
86
|
|
|
* |
87
|
|
|
* @param string $name Name |
88
|
|
|
* @param mixed $value Value |
89
|
|
|
* |
90
|
|
|
* @author Donii Sergii <[email protected]> |
91
|
|
|
*/ |
92
|
|
|
public function __set($name, $value) |
93
|
|
|
{ |
94
|
|
|
$this->items[$name] = $value; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|