|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the Laudis Neo4j package. |
| 7 | + * |
| 8 | + * (c) Laudis technologies <http://laudis.tech> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Laudis\Neo4j\Types; |
| 15 | + |
| 16 | +use BadMethodCallException; |
| 17 | +use function get_class; |
| 18 | +use InvalidArgumentException; |
| 19 | +use Laudis\Neo4j\Contracts\CypherContainerInterface; |
| 20 | +use function sprintf; |
| 21 | + |
| 22 | +/** |
| 23 | + * @implements CypherContainerInterface<string, CypherContainerInterface|scalar|null> |
| 24 | + */ |
| 25 | +abstract class AbstractCypherContainer implements CypherContainerInterface |
| 26 | +{ |
| 27 | + public function jsonSerialize() |
| 28 | + { |
| 29 | + $tbr = []; |
| 30 | + |
| 31 | + foreach ($this as $key => $value) { |
| 32 | + $tbr[$key] = $value; |
| 33 | + } |
| 34 | + |
| 35 | + return $tbr; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @psalm-suppress UnusedVariable |
| 40 | + */ |
| 41 | + public function offsetExists($offset): bool |
| 42 | + { |
| 43 | + foreach ($this as $key => $value) { |
| 44 | + if ($key === $offset) { |
| 45 | + return true; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + return false; |
| 50 | + } |
| 51 | + |
| 52 | + public function offsetGet($offset) |
| 53 | + { |
| 54 | + foreach ($this as $key => $value) { |
| 55 | + if ($key === $offset) { |
| 56 | + return $value; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + throw new InvalidArgumentException("Offset: $offset does not exists for class: ".static::class); |
| 61 | + } |
| 62 | + |
| 63 | + public function offsetSet($offset, $value): void |
| 64 | + { |
| 65 | + throw new BadMethodCallException(sprintf('%s is immutable', get_class($this))); |
| 66 | + } |
| 67 | + |
| 68 | + public function offsetUnset($offset): void |
| 69 | + { |
| 70 | + throw new BadMethodCallException(sprintf('%s is immutable', get_class($this))); |
| 71 | + } |
| 72 | +} |
0 commit comments