-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecuteData.php
More file actions
64 lines (51 loc) · 1.24 KB
/
ExecuteData.php
File metadata and controls
64 lines (51 loc) · 1.24 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
<?php
namespace SyncEngine\Service;
use SyncEngine\Structure\Data\ResourceData;
class ExecuteData extends ResourceData
{
protected bool $raw = false;
public function __construct( $array = [], int $flags = 0, string $iteratorClass = "ArrayIterator" ) {
if ( ! is_iterable( $array ) && ! is_object( $array ) ) {
$this->raw = true;
$array = [ 'raw' => $array ];
}
parent::__construct( $array, $flags, $iteratorClass );
}
public function isRaw(): bool
{
return $this->raw;
}
public function get( $key = null, $default = null ): mixed
{
if ( $this->isRaw() ) {
if ( $this->isKey( $key ) ) {
return $default;
}
return parent::get( 'raw', $default );
}
return parent::get( $key, $default );
}
public function set( $value, $key = null ): static
{
if ( $this->isKey( $key ) ) {
if ( $this->isRaw() ) {
return $this; // @todo error?
}
return parent::set( $value, $key );
}
if ( ! is_iterable( $value ) && ! is_object( $value ) ) {
$this->raw = true;
return parent::set( $value, 'raw' );
} else {
$this->raw = false;
return parent::set( $value );
}
}
public function __toString(): string
{
if ( $this->isRaw() ) {
return (string) $this->get();
}
return parent::__toString();
}
}