PublicScopeSimulator
in package
Generates code necessary to simulate a fatal error in case of unauthorized access to class members in magic methods even when in child classes and dealing with protected members.
Table of Contents
Constants
- OPERATION_GET = 'get'
- OPERATION_ISSET = 'isset'
- OPERATION_SET = 'set'
- OPERATION_UNSET = 'unset'
Methods
- getPublicAccessSimulationCode() : string
- Generates code for simulating access to a property from the scope that is accessing a proxy.
- generateScopeReBind() : string
- Generates code to bind operations to the parent scope
- getByRefReturnValue() : string
- Defines whether the given operation produces a reference.
- getOperation() : string
- getTargetObject() : string
- Retrieves the logic to fetch the object on which access should be attempted
- getUndefinedPropertyNotice() : string
- This will generate code that triggers a notice if access is attempted on a non-existing property
Constants
OPERATION_GET
public
mixed
OPERATION_GET
= 'get'
OPERATION_ISSET
public
mixed
OPERATION_ISSET
= 'isset'
OPERATION_SET
public
mixed
OPERATION_SET
= 'set'
OPERATION_UNSET
public
mixed
OPERATION_UNSET
= 'unset'
Methods
getPublicAccessSimulationCode()
Generates code for simulating access to a property from the scope that is accessing a proxy.
public
static getPublicAccessSimulationCode(string $operationType, string $nameParameter[, string|null $valueParameter = null ][, PropertyGenerator $valueHolder = null ][, string|null $returnPropertyName = null ][, ReflectionClass|null $originalClass = null ]) : string
This is done by introspecting debug_backtrace()
and then binding a closure to the scope
of the parent caller.
Parameters
- $operationType : string
-
operation to execute: one of 'get', 'set', 'isset' or 'unset'
- $nameParameter : string
-
name of the
name
parameter of the magic method - $valueParameter : string|null = null
-
name of the
value
parameter of the magic method, only to be used with $operationType 'set' - $valueHolder : PropertyGenerator = null
-
name of the property containing the target object from which to read the property.
$this
if none provided - $returnPropertyName : string|null = null
-
name of the property to which we want to assign the result of the operation. Return directly if none provided
- $originalClass : ReflectionClass|null = null
Tags
Return values
stringgenerateScopeReBind()
Generates code to bind operations to the parent scope
private
static generateScopeReBind() : string
Return values
stringgetByRefReturnValue()
Defines whether the given operation produces a reference.
private
static getByRefReturnValue(string $operationType) : string
Note: if the object is a wrapper, the wrapped instance is accessed directly. If the object is a ghost or the proxy has no wrapper, then an instance of the parent class is created via on-the-fly unserialization
Parameters
- $operationType : string
Tags
Return values
stringgetOperation()
private
static getOperation(string $operationType, string $nameParameter, string|null $valueParameter) : string
Parameters
- $operationType : string
- $nameParameter : string
- $valueParameter : string|null
Tags
Return values
stringgetTargetObject()
Retrieves the logic to fetch the object on which access should be attempted
private
static getTargetObject([PropertyGenerator|null $valueHolder = null ]) : string
Parameters
- $valueHolder : PropertyGenerator|null = null
Return values
stringgetUndefinedPropertyNotice()
This will generate code that triggers a notice if access is attempted on a non-existing property
private
static getUndefinedPropertyNotice(string $operationType, string $nameParameter[, string|null $interfaceName = null ]) : string
Parameters
- $operationType : string
- $nameParameter : string
- $interfaceName : string|null = null