-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathAbstractDocument.php
More file actions
138 lines (124 loc) · 2.75 KB
/
AbstractDocument.php
File metadata and controls
138 lines (124 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/*
* This file is part of the Solarium package.
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code.
*/
namespace Solarium\Core\Query;
/**
* Document base functionality, used by readonly and readwrite documents.
*/
abstract class AbstractDocument implements DocumentInterface, \IteratorAggregate, \Countable, \ArrayAccess, \JsonSerializable
{
/**
* All fields in this document.
*/
protected array $fields;
/**
* @param string $name
* @param mixed $value
*/
abstract public function __set(string $name, mixed $value): void;
/**
* Get field value by name.
*
* Magic access method for accessing fields as properties of this document
* object, by field name.
*
* @param string $name
*
* @return mixed
*/
public function __get(string $name): mixed
{
return $this->fields[$name] ?? null;
}
/**
* Check if field is set by name.
*
* Magic method for checking if fields are set as properties of this document
* object, by field name. Also used by empty().
*
* @param string $name
*
* @return bool
*/
public function __isset(string $name): bool
{
return isset($this->fields[$name]);
}
/**
* Get all fields.
*
* @return array
*/
public function getFields(): array
{
return $this->fields;
}
/**
* IteratorAggregate implementation.
*
* @return \ArrayIterator
*/
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->fields);
}
/**
* Countable implementation.
*
* @return int
*/
public function count(): int
{
return \count($this->fields);
}
/**
* ArrayAccess implementation.
*
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value): void
{
$this->__set($offset, $value);
}
/**
* ArrayAccess implementation.
*
* @param mixed $offset
*
* @return bool
*/
public function offsetExists($offset): bool
{
return null !== $this->__get($offset);
}
/**
* ArrayAccess implementation.
*
* @param mixed $offset
*/
public function offsetUnset($offset): void
{
$this->__set($offset, null);
}
/**
* ArrayAccess implementation.
*
* @param mixed $offset
*
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->__get($offset);
}
/**
* {@inheritdoc}
*/
abstract public function jsonSerialize(): mixed;
}