Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

GeneratorProxyTrait.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Repository\Values;
8
9 use Generator;
10
18 trait GeneratorProxyTrait
19 {
25 protected $object;
26
32 protected $id;
33
35 private $generator;
36
43 public function __construct(Generator $generator, $id)
44 {
45 $this->generator = $generator;
46 $this->id = $id;
47 }
48
49 public function __call($name, $arguments)
50 {
51 if ($this->object === null) {
52 $this->loadObject();
53 }
54
55 return $this->object->$name(...$arguments);
56 }
57
58 public function __invoke(...$args)
59 {
60 if ($this->object === null) {
61 $this->loadObject();
62 }
63
64 return ($this->object)(...$args);
65 }
66
67 public function __get($name)
68 {
69 if ($name === 'id') {
70 return $this->id;
71 }
72
73 if ($this->object === null) {
74 $this->loadObject();
75 }
76
77 return $this->object->$name;
78 }
79
80 public function __isset($name)
81 {
82 if ($name === 'id') {
83 return true;
84 }
85
86 if ($this->object === null) {
87 $this->loadObject();
88 }
89
90 return isset($this->object->$name);
91 }
92
93 public function __unset($name)
94 {
95 if ($this->object === null) {
96 $this->loadObject();
97 }
98
99 unset($this->object->$name);
100 }
101
102 public function __set($name, $value)
103 {
104 if ($this->object === null) {
105 $this->loadObject();
106 }
107
108 $this->object->$name = $value;
109 }
110
111 public function __toString()
112 {
113 if ($this->object === null) {
114 $this->loadObject();
115 }
116
117 return (string)$this->object;
118 }
119
120 public function __sleep()
121 {
122 if ($this->object === null) {
123 $this->loadObject();
124 }
125
126 return ['object', 'id'];
127 }
128
129 public function __debugInfo()
130 {
131 if ($this->object === null) {
132 $this->loadObject();
133 }
134
135 return [
136 'object' => $this->object,
137 'id' => $this->id,
138 ];
139 }
140
150 protected function loadObject()
151 {
152 $this->object = $this->generator->send($this->id);
153 $this->generator->next();
154 unset($this->generator);
155 }
156 }
eZ\Publish\Core\Repository\Values\__construct
__construct(Generator $generator, $id)
GeneratorProxyTrait constructor.
Definition: GeneratorProxyTrait.php:43
eZ\Publish\Core\Repository\Values\$generator
$generator
Definition: GeneratorProxyTrait.php:35
eZ\Publish\Core\Repository\Values\__unset
__unset($name)
Definition: GeneratorProxyTrait.php:93
eZ\Publish\Core\Repository\Values\loadObject
loadObject()
Loads the generator to object value and unset's generator.
Definition: GeneratorProxyTrait.php:150
eZ\Publish\Core\Repository\Values\__invoke
__invoke(... $args)
Definition: GeneratorProxyTrait.php:58
eZ\Publish\Core\Repository\Values\__set
__set($name, $value)
Definition: GeneratorProxyTrait.php:102
eZ\Publish\Core\Repository\Values\__get
__get($name)
Definition: GeneratorProxyTrait.php:67
eZ\Publish\Core\Repository\Values\__call
__call($name, $arguments)
Definition: GeneratorProxyTrait.php:49
eZ\Publish\Core\Repository\Values\__debugInfo
__debugInfo()
Definition: GeneratorProxyTrait.php:129
eZ\Publish\Core\Repository\Values\__toString
__toString()
Definition: GeneratorProxyTrait.php:111
eZ\Publish\Core\Repository\Values\__isset
__isset($name)
Definition: GeneratorProxyTrait.php:80
eZ\Publish\Core\Repository\Values\GeneratorProxyTrait
trait GeneratorProxyTrait
Trait for proxies, covers all relevant magic methods and exposes private method to load object.
Definition: GeneratorProxyTrait.php:19
eZ\Publish\Core\Repository\Values\__sleep
__sleep()
Definition: GeneratorProxyTrait.php:120
eZ\Publish\Core\Repository\Values\$id
$id
Definition: GeneratorProxyTrait.php:32
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.