Documentation

Instantiator
in package
implements InstantiatorInterface

FinalYes

Table of Contents

Interfaces

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

Constants

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.

Properties

$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.

Methods

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

private 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.

This constant will be private in 2.0

private 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(string $className) : object
Parameters
$className : string
Tags
phpstan-param

class-string<T> $className

phpstan-return

T

throws
ExceptionInterface
template

T of object

Return values
object

attemptInstantiationViaUnSerialization()

private attemptInstantiationViaUnSerialization(ReflectionClass $reflectionClass, string $serializedString) : void
Parameters
$reflectionClass : ReflectionClass
$serializedString : string
Tags
phpstan-param

ReflectionClass<T> $reflectionClass

throws
UnexpectedValueException
template

T of object

buildAndCacheFromFactory()

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

private buildAndCacheFromFactory(string $className) : object
Parameters
$className : string
Tags
phpstan-param

class-string<T> $className

phpstan-return

T

template

T of object

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

class-string<T> $className

phpstan-return

callable(): T

throws
InvalidArgumentException
throws
UnexpectedValueException
throws
ReflectionException
template

T of object

Return values
callable

checkIfUnSerializationIsSupported()

private checkIfUnSerializationIsSupported(ReflectionClass $reflectionClass, string $serializedString) : void
Parameters
$reflectionClass : ReflectionClass
$serializedString : string
Tags
phpstan-param

ReflectionClass<T> $reflectionClass

throws
UnexpectedValueException
template

T of object

getReflectionClass()

private getReflectionClass(string $className) : ReflectionClass
Parameters
$className : string
Tags
phpstan-param

class-string<T> $className

phpstan-return

ReflectionClass<T>

throws
InvalidArgumentException
throws
ReflectionException
template

T of object

Return values
ReflectionClass

hasInternalAncestors()

Verifies whether the given class is to be considered internal

private hasInternalAncestors(ReflectionClass $reflectionClass) : bool
Parameters
$reflectionClass : ReflectionClass
Tags
phpstan-param

ReflectionClass<T> $reflectionClass

template

T of object

Return values
bool

isInstantiableViaReflection()

private isInstantiableViaReflection(ReflectionClass $reflectionClass) : bool
Parameters
$reflectionClass : ReflectionClass
Tags
phpstan-param

ReflectionClass<T> $reflectionClass

template

T of object

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

ReflectionClass<T> $reflectionClass

template

T of object

Return values
bool

        
On this page

Search results