FileAccess Orion

DebugClassLoader
in package

Autoloader checking if the class is really defined in the file found.

The ClassLoader will wrap all registered autoloaders and will throw an exception if a file is found but does not declare the class.

It can also patch classes to turn docblocks into actual return types. This behavior is controlled by the SYMFONY_PATCH_TYPE_DECLARATIONS env var, which is a url-encoded array with the follow parameters:

  • "force": any value enables deprecation notices - can be any of:
    • "docblock" to patch only docblock annotations
    • "object" to turn union types to the "object" type when possible (not recommended)
    • "1" to add all possible return types including magic methods
    • "0" to add possible return types excluding magic methods
  • "php": the target version of PHP - e.g. "7.1" doesn't generate "object" types
  • "deprecations": "1" to trigger a deprecation notice when a child class misses a return type while the parent declares an "@return" annotation

Note that patching doesn't care about any coding style so you'd better to run php-cs-fixer after, with rules "phpdoc_trim_consecutive_blank_line_separation" and "no_superfluous_phpdoc_tags" enabled typically.

Tags
author

Fabien Potencier fabien@symfony.com

author

Christophe Coevoet stof@notk.org

author

Nicolas Grekas p@tchwork.com

author

Guilhem Niot guilhem.niot@gmail.com

Table of Contents

BUILTIN_RETURN_TYPES  = ['void' => true, 'array' => true, 'bool' => true, 'callable' => true, 'float' => true, 'int' => true, 'iterable' => true, 'object' => true, 'string' => true, 'self' => true, 'parent' => true]
INTERNAL_TYPES  = ['ArrayAccess' => ['offsetExists' => 'bool', 'offsetSet' => 'void', 'offsetUnset' => 'void'], 'Countable' => ['count' => 'int'], 'Iterator' => ['next' => 'void', 'valid' => 'bool', 'rewind' => 'void'], 'IteratorAggregate' => ['getIterator' => '\\Traversable'], 'OuterIterator' => ['getInnerIterator' => '\\Iterator'], 'RecursiveIterator' => ['hasChildren' => 'bool'], 'SeekableIterator' => ['seek' => 'void'], 'Serializable' => ['serialize' => 'string', 'unserialize' => 'void'], 'SessionHandlerInterface' => ['open' => 'bool', 'close' => 'bool', 'read' => 'string', 'write' => 'bool', 'destroy' => 'bool', 'gc' => 'bool'], 'SessionIdInterface' => ['create_sid' => 'string'], 'SessionUpdateTimestampHandlerInterface' => ['validateId' => 'bool', 'updateTimestamp' => 'bool'], 'Throwable' => ['getMessage' => 'string', 'getCode' => 'int', 'getFile' => 'string', 'getLine' => 'int', 'getTrace' => 'array', 'getPrevious' => '?\\Throwable', 'getTraceAsString' => 'string']]
MAGIC_METHODS  = ['__set' => 'void', '__isset' => 'bool', '__unset' => 'void', '__sleep' => 'array', '__wakeup' => 'void', '__toString' => 'string', '__clone' => 'void', '__debugInfo' => 'array', '__serialize' => 'array', '__unserialize' => 'void']
SPECIAL_RETURN_TYPES  = ['mixed' => 'mixed', 'void' => 'void', 'null' => 'null', 'resource' => 'resource', 'static' => 'object', '$this' => 'object', 'boolean' => 'bool', 'true' => 'bool', 'false' => 'bool', 'integer' => 'int', 'array' => 'array', 'bool' => 'bool', 'callable' => 'callable', 'float' => 'float', 'int' => 'int', 'iterable' => 'iterable', 'object' => 'object', 'string' => 'string', 'self' => 'self', 'parent' => 'parent']
$annotatedParameters  : mixed
$caseCheck  : mixed
$checkedClasses  : mixed
$classLoader  : mixed
$darwinCache  : mixed
$deprecated  : mixed
$fileOffsets  : mixed
$final  : mixed
$finalMethods  : mixed
$internal  : mixed
$internalMethods  : mixed
$isFinder  : mixed
$loaded  : mixed
$method  : mixed
$methodTraits  : mixed
$patchTypes  : mixed
$returnTypes  : mixed
__construct()  : mixed
checkAnnotations()  : array<string|int, mixed>
checkCase()  : array<string|int, mixed>|null
checkClasses()  : bool
disable()  : void
Disables the wrapping.
enable()  : void
Wraps all autoloaders.
findFile()  : string|null
getClassLoader()  : callable
Gets the wrapped class loader.
loadClass()  : void
Loads the given class or interface.
checkClass()  : void
darwinRealpath()  : string
`realpath` on MacOSX doesn't normalize the case of characters.
fixReturnStatements()  : mixed
getOwnInterfaces()  : array<string|int, string>
`class_implements` includes interfaces from the parents so we have to manually exclude them.
getUseStatements()  : array<string|int, mixed>
normalizeType()  : string
patchMethod()  : mixed
Utility method to add @return annotations to the Symfony code-base where it triggers a self-deprecations.
setReturnType()  : void

Constants

BUILTIN_RETURN_TYPES

private mixed BUILTIN_RETURN_TYPES = ['void' => true, 'array' => true, 'bool' => true, 'callable' => true, 'float' => true, 'int' => true, 'iterable' => true, 'object' => true, 'string' => true, 'self' => true, 'parent' => true]

INTERNAL_TYPES

private mixed INTERNAL_TYPES = ['ArrayAccess' => ['offsetExists' => 'bool', 'offsetSet' => 'void', 'offsetUnset' => 'void'], 'Countable' => ['count' => 'int'], 'Iterator' => ['next' => 'void', 'valid' => 'bool', 'rewind' => 'void'], 'IteratorAggregate' => ['getIterator' => '\\Traversable'], 'OuterIterator' => ['getInnerIterator' => '\\Iterator'], 'RecursiveIterator' => ['hasChildren' => 'bool'], 'SeekableIterator' => ['seek' => 'void'], 'Serializable' => ['serialize' => 'string', 'unserialize' => 'void'], 'SessionHandlerInterface' => ['open' => 'bool', 'close' => 'bool', 'read' => 'string', 'write' => 'bool', 'destroy' => 'bool', 'gc' => 'bool'], 'SessionIdInterface' => ['create_sid' => 'string'], 'SessionUpdateTimestampHandlerInterface' => ['validateId' => 'bool', 'updateTimestamp' => 'bool'], 'Throwable' => ['getMessage' => 'string', 'getCode' => 'int', 'getFile' => 'string', 'getLine' => 'int', 'getTrace' => 'array', 'getPrevious' => '?\\Throwable', 'getTraceAsString' => 'string']]

MAGIC_METHODS

private mixed MAGIC_METHODS = ['__set' => 'void', '__isset' => 'bool', '__unset' => 'void', '__sleep' => 'array', '__wakeup' => 'void', '__toString' => 'string', '__clone' => 'void', '__debugInfo' => 'array', '__serialize' => 'array', '__unserialize' => 'void']

SPECIAL_RETURN_TYPES

private mixed SPECIAL_RETURN_TYPES = ['mixed' => 'mixed', 'void' => 'void', 'null' => 'null', 'resource' => 'resource', 'static' => 'object', '$this' => 'object', 'boolean' => 'bool', 'true' => 'bool', 'false' => 'bool', 'integer' => 'int', 'array' => 'array', 'bool' => 'bool', 'callable' => 'callable', 'float' => 'float', 'int' => 'int', 'iterable' => 'iterable', 'object' => 'object', 'string' => 'string', 'self' => 'self', 'parent' => 'parent']

Properties

Methods

__construct()

public __construct(callable $classLoader) : mixed
Parameters
$classLoader : callable
Return values
mixed

checkAnnotations()

public checkAnnotations(ReflectionClass $refl, string $class) : array<string|int, mixed>
Parameters
$refl : ReflectionClass
$class : string
Return values
array<string|int, mixed>

checkCase()

public checkCase(ReflectionClass $refl, string $file, string $class) : array<string|int, mixed>|null
Parameters
$refl : ReflectionClass
$file : string
$class : string
Return values
array<string|int, mixed>|null

checkClasses()

public static checkClasses() : bool
Return values
bool

disable()

Disables the wrapping.

public static disable() : void
Return values
void

enable()

Wraps all autoloaders.

public static enable() : void
Return values
void

findFile()

public findFile(string $class) : string|null
Parameters
$class : string
Return values
string|null

getClassLoader()

Gets the wrapped class loader.

public getClassLoader() : callable
Return values
callable

The wrapped class loader

loadClass()

Loads the given class or interface.

public loadClass(string $class) : void
Parameters
$class : string
Tags
throws
RuntimeException
Return values
void

checkClass()

private checkClass(string $class[, string $file = null ]) : void
Parameters
$class : string
$file : string = null
Return values
void

darwinRealpath()

`realpath` on MacOSX doesn't normalize the case of characters.

private darwinRealpath(string $real) : string
Parameters
$real : string
Return values
string

fixReturnStatements()

private fixReturnStatements(ReflectionMethod $method, string $returnType) : mixed
Parameters
$method : ReflectionMethod
$returnType : string
Return values
mixed

getOwnInterfaces()

`class_implements` includes interfaces from the parents so we have to manually exclude them.

private getOwnInterfaces(string $class, string|null $parent) : array<string|int, string>
Parameters
$class : string
$parent : string|null
Return values
array<string|int, string>

getUseStatements()

private static getUseStatements(string $file) : array<string|int, mixed>
Parameters
$file : string
Return values
array<string|int, mixed>

normalizeType()

private normalizeType(string $type, string $class, string|null $parent) : string
Parameters
$type : string
$class : string
$parent : string|null
Return values
string

patchMethod()

Utility method to add @return annotations to the Symfony code-base where it triggers a self-deprecations.

private patchMethod(ReflectionMethod $method, string $returnType, string $declaringFile, string $normalizedType) : mixed
Parameters
$method : ReflectionMethod
$returnType : string
$declaringFile : string
$normalizedType : string
Return values
mixed

setReturnType()

private setReturnType(string $types, ReflectionMethod $method, string|null $parent) : void
Parameters
$types : string
$method : ReflectionMethod
$parent : string|null
Return values
void

Search results