Documentation

Instantiator
in package
implements InstantiatorInterface

Interfaces, Classes and Traits

InstantiatorInterface
Instantiator provides utility methods to build objects without invoking their constructors

Table of Contents

SERIALIZATION_FORMAT_AVOID_UNSERIALIZER  = 'O'
SERIALIZATION_FORMAT_USE_UNSERIALIZER  = 'C'
Markers used internally by PHP to define whether {@see \unserialize} should invoke the method {@see \Serializable::unserialize()} when dealing with classes implementing the {@see \Serializable} interface.
$cachedCloneables  : array<string|int, object>
Array of objects that can directly be cloned, indexed by class name.
$cachedInstantiators  : array<string|int, callable>
Used to instantiate specific classes, indexed by class name.
instantiate()  : object
attemptInstantiationViaUnSerialization()  : void
buildAndCacheFromFactory()  : object
Builds the requested object and caches it in static properties for performance
buildFactory()  : callable
Builds a callable capable of instantiating the given $className without invoking its constructor.
checkIfUnSerializationIsSupported()  : void
getReflectionClass()  : ReflectionClass
hasInternalAncestors()  : bool
Verifies whether the given class is to be considered internal
isInstantiableViaReflection()  : bool
isSafeToClone()  : bool
Checks if a class is cloneable

Constants

SERIALIZATION_FORMAT_AVOID_UNSERIALIZER

public mixed SERIALIZATION_FORMAT_AVOID_UNSERIALIZER = 'O'

SERIALIZATION_FORMAT_USE_UNSERIALIZER

Markers used internally by PHP to define whether {@see \unserialize} should invoke the method {@see \Serializable::unserialize()} when dealing with classes implementing the {@see \Serializable} interface.

public mixed SERIALIZATION_FORMAT_USE_UNSERIALIZER = 'C'

Properties

$cachedCloneables

Array of objects that can directly be cloned, indexed by class name.

private static array<string|int, object> $cachedCloneables = []

$cachedInstantiators

Used to instantiate specific classes, indexed by class name.

private static array<string|int, callable> $cachedInstantiators = []

Methods

instantiate()

public instantiate(mixed $className) : object
Parameters
$className : mixed
Return values
object

attemptInstantiationViaUnSerialization()

private attemptInstantiationViaUnSerialization(ReflectionClass $reflectionClass, string $serializedString) : void
Parameters
$reflectionClass : ReflectionClass
$serializedString : string
Tags
throws
UnexpectedValueException
template

T of object

phpstan-param

ReflectionClass $reflectionClass

Return values
void

buildAndCacheFromFactory()

Builds the requested object and caches it in static properties for performance

private buildAndCacheFromFactory(string $className) : object
Parameters
$className : string
Tags
template

T of object

phpstan-param

class-string $className

phpstan-return

T

Return values
object

buildFactory()

Builds a callable capable of instantiating the given $className without invoking its constructor.

private buildFactory(string $className) : callable
Parameters
$className : string
Tags
throws
InvalidArgumentException
throws
UnexpectedValueException
throws
ReflectionException
template

T of object

phpstan-param

class-string $className

phpstan-return

callable(): T

Return values
callable

checkIfUnSerializationIsSupported()

private checkIfUnSerializationIsSupported(ReflectionClass $reflectionClass, string $serializedString) : void
Parameters
$reflectionClass : ReflectionClass
$serializedString : string
Tags
throws
UnexpectedValueException
template

T of object

phpstan-param

ReflectionClass $reflectionClass

Return values
void

getReflectionClass()

private getReflectionClass(string $className) : ReflectionClass
Parameters
$className : string
Tags
throws
InvalidArgumentException
throws
ReflectionException
template

T of object

phpstan-param

class-string $className

phpstan-return

ReflectionClass

Return values
ReflectionClass

hasInternalAncestors()

Verifies whether the given class is to be considered internal

private hasInternalAncestors(ReflectionClass $reflectionClass) : bool
Parameters
$reflectionClass : ReflectionClass
Tags
template

T of object

phpstan-param

ReflectionClass $reflectionClass

Return values
bool

isInstantiableViaReflection()

private isInstantiableViaReflection(ReflectionClass $reflectionClass) : bool
Parameters
$reflectionClass : ReflectionClass
Tags
template

T of object

phpstan-param

ReflectionClass $reflectionClass

Return values
bool

isSafeToClone()

Checks if a class is cloneable

private isSafeToClone(ReflectionClass $reflectionClass) : bool

Classes implementing __clone cannot be safely cloned, as that may cause side-effects.

Parameters
$reflectionClass : ReflectionClass
Tags
template

T of object

phpstan-param

ReflectionClass $reflectionClass

Return values
bool

Search results