Documentation

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

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
psalm-param

$operationType self::OPERATION_*

throws
InvalidArgumentException
Return values
string

generateScopeReBind()

Generates code to bind operations to the parent scope

private static generateScopeReBind() : string
Return values
string

getByRefReturnValue()

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
psalm-param

$operationType self::OPERATION_*

Return values
string

getOperation()

private static getOperation(string $operationType, string $nameParameter, string|null $valueParameter) : string
Parameters
$operationType : string
$nameParameter : string
$valueParameter : string|null
Tags
psalm-param

$operationType self::OPERATION_*

throws
InvalidArgumentException
Return values
string

getTargetObject()

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
string

getUndefinedPropertyNotice()

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
Tags
psalm-param

$operationType self::OPERATION_*

Return values
string

        
On this page

Search results