@@ -32,17 +32,24 @@ final class ReadAccessor
3232 public const TYPE_SOURCE = 4 ;
3333 public const TYPE_ARRAY_ACCESS = 5 ;
3434
35+ public const EXTRACT_IS_UNDEFINED_CALLBACK = 'extractIsUndefinedCallbacks ' ;
36+ public const EXTRACT_IS_NULL_CALLBACK = 'extractIsNullCallbacks ' ;
37+ public const EXTRACT_CALLBACK = 'extractCallbacks ' ;
38+ public const EXTRACT_TARGET_IS_UNDEFINED_CALLBACK = 'extractTargetIsUndefinedCallbacks ' ;
39+ public const EXTRACT_TARGET_IS_NULL_CALLBACK = 'extractTargetIsNullCallbacks ' ;
40+ public const EXTRACT_TARGET_CALLBACK = 'extractTargetCallbacks ' ;
41+
3542 /**
3643 * @param array<string, string> $context
3744 */
3845 public function __construct (
39- private readonly int $ type ,
40- private readonly string $ accessor ,
41- private readonly ?string $ sourceClass = null ,
42- private readonly bool $ private = false ,
43- private readonly ?string $ property = null ,
46+ public readonly int $ type ,
47+ public readonly string $ accessor ,
48+ public readonly ?string $ sourceClass = null ,
49+ public readonly bool $ private = false ,
50+ public readonly ?string $ property = null ,
4451 // will be the name of the property if different from accessor
45- private readonly array $ context = [],
52+ public readonly array $ context = [],
4653 ) {
4754 if (self ::TYPE_METHOD === $ this ->type && null === $ this ->sourceClass ) {
4855 throw new InvalidArgumentException ('Source class must be provided when using "method" type. ' );
@@ -54,7 +61,7 @@ public function __construct(
5461 *
5562 * @throws CompileException
5663 */
57- public function getExpression (Expr $ input ): Expr
64+ public function getExpression (Expr $ input, bool $ target = false ): Expr
5865 {
5966 if (self ::TYPE_METHOD === $ this ->type ) {
6067 $ methodCallArguments = [];
@@ -99,7 +106,7 @@ public function getExpression(Expr $input): Expr
99106 * $this->extractCallbacks['method_name']($input)
100107 */
101108 return new Expr \FuncCall (
102- new Expr \ArrayDimFetch (new Expr \PropertyFetch (new Expr \Variable ('this ' ), ' extractCallbacks ' ), new Scalar \String_ ($ this ->property ?? $ this ->accessor )),
109+ new Expr \ArrayDimFetch (new Expr \PropertyFetch (new Expr \Variable ('this ' ), $ target ? self :: EXTRACT_TARGET_CALLBACK : self :: EXTRACT_CALLBACK ), new Scalar \String_ ($ this ->property ?? $ this ->accessor )),
103110 [
104111 new Arg ($ input ),
105112 ]
@@ -124,7 +131,7 @@ public function getExpression(Expr $input): Expr
124131 * $this->extractCallbacks['property_name']($input)
125132 */
126133 return new Expr \FuncCall (
127- new Expr \ArrayDimFetch (new Expr \PropertyFetch (new Expr \Variable ('this ' ), ' extractCallbacks ' ), new Scalar \String_ ($ this ->accessor )),
134+ new Expr \ArrayDimFetch (new Expr \PropertyFetch (new Expr \Variable ('this ' ), $ target ? self :: EXTRACT_TARGET_CALLBACK : self :: EXTRACT_CALLBACK ), new Scalar \String_ ($ this ->accessor )),
128135 [
129136 new Arg ($ input ),
130137 ]
@@ -155,7 +162,7 @@ public function getExpression(Expr $input): Expr
155162 throw new CompileException ('Invalid accessor for read expression ' );
156163 }
157164
158- public function getIsDefinedExpression (Expr \Variable $ input , bool $ nullable = false ): ?Expr
165+ public function getIsDefinedExpression (Expr \Variable $ input , bool $ nullable = false , bool $ target = false ): ?Expr
159166 {
160167 // It is not possible to check if the underlying data is defined, assumes it is, php will throw an error if it is not
161168 if (!$ nullable && \in_array ($ this ->type , [self ::TYPE_METHOD , self ::TYPE_SOURCE ])) {
@@ -172,7 +179,7 @@ public function getIsDefinedExpression(Expr\Variable $input, bool $nullable = fa
172179 * !$this->extractIsUndefinedCallbacks['property_name']($input)
173180 */
174181 return new Expr \BooleanNot (new Expr \FuncCall (
175- new Expr \ArrayDimFetch (new Expr \PropertyFetch (new Expr \Variable ('this ' ), ' extractIsUndefinedCallbacks ' ), new Scalar \String_ ($ this ->accessor )),
182+ new Expr \ArrayDimFetch (new Expr \PropertyFetch (new Expr \Variable ('this ' ), $ target ? self :: EXTRACT_TARGET_IS_UNDEFINED_CALLBACK : self :: EXTRACT_IS_UNDEFINED_CALLBACK ), new Scalar \String_ ($ this ->accessor )),
176183 [
177184 new Arg ($ input ),
178185 ]
@@ -212,7 +219,7 @@ public function getIsDefinedExpression(Expr\Variable $input, bool $nullable = fa
212219 return null ;
213220 }
214221
215- public function getIsNullExpression (Expr \Variable $ input ): Expr
222+ public function getIsNullExpression (Expr \Variable $ input, bool $ target = false ): Expr
216223 {
217224 if (self ::TYPE_METHOD === $ this ->type ) {
218225 $ methodCallExpr = $ this ->getExpression ($ input );
@@ -236,7 +243,7 @@ public function getIsNullExpression(Expr\Variable $input): Expr
236243 * $this->extractIsNullCallbacks['property_name']($input)
237244 */
238245 return new Expr \FuncCall (
239- new Expr \ArrayDimFetch (new Expr \PropertyFetch (new Expr \Variable ('this ' ), ' extractIsNullCallbacks ' ), new Scalar \String_ ($ this ->accessor )),
246+ new Expr \ArrayDimFetch (new Expr \PropertyFetch (new Expr \Variable ('this ' ), $ target ? self :: EXTRACT_TARGET_IS_NULL_CALLBACK : self :: EXTRACT_IS_NULL_CALLBACK ), new Scalar \String_ ($ this ->accessor )),
240247 [
241248 new Arg ($ input ),
242249 ]
@@ -270,7 +277,7 @@ public function getIsNullExpression(Expr\Variable $input): Expr
270277 throw new CompileException ('Invalid accessor for read expression ' );
271278 }
272279
273- public function getIsUndefinedExpression (Expr \Variable $ input ): Expr
280+ public function getIsUndefinedExpression (Expr \Variable $ input, bool $ target = false ): Expr
274281 {
275282 if (\in_array ($ this ->type , [self ::TYPE_METHOD , self ::TYPE_SOURCE ])) {
276283 /*
@@ -289,7 +296,7 @@ public function getIsUndefinedExpression(Expr\Variable $input): Expr
289296 * $this->extractIsUndefinedCallbacks['property_name']($input)
290297 */
291298 return new Expr \FuncCall (
292- new Expr \ArrayDimFetch (new Expr \PropertyFetch (new Expr \Variable ('this ' ), ' extractIsUndefinedCallbacks ' ), new Scalar \String_ ($ this ->accessor )),
299+ new Expr \ArrayDimFetch (new Expr \PropertyFetch (new Expr \Variable ('this ' ), $ target ? self :: EXTRACT_TARGET_IS_UNDEFINED_CALLBACK : self :: EXTRACT_IS_UNDEFINED_CALLBACK ), new Scalar \String_ ($ this ->accessor )),
293300 [
294301 new Arg ($ input ),
295302 ]
0 commit comments