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:
- "phpdoc" to patch only docblock annotations
- "2" to add all possible return types
- "1" to add return types but only to tests/final/internal/private 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
Table of Contents
Constants
- BUILTIN_RETURN_TYPES = ['void' => true, 'array' => true, 'false' => true, 'bool' => true, 'callable' => true, 'float' => true, 'int' => true, 'iterable' => true, 'object' => true, 'string' => true, 'self' => true, 'parent' => true, 'mixed' => true, 'static' => true, 'null' => true, 'true' => true, 'never' => true]
- MAGIC_METHODS = ['__isset' => 'bool', '__sleep' => 'array', '__toString' => 'string', '__debugInfo' => 'array', '__serialize' => 'array']
- SPECIAL_RETURN_TYPES = ['void' => 'void', 'null' => 'null', 'resource' => 'resource', 'boolean' => 'bool', 'true' => 'true', 'false' => 'false', 'integer' => 'int', 'array' => 'array', 'bool' => 'bool', 'callable' => 'callable', 'float' => 'float', 'int' => 'int', 'iterable' => 'iterable', 'object' => 'object', 'string' => 'string', 'self' => 'self', 'parent' => 'parent', 'mixed' => 'mixed', 'static' => 'static', '$this' => 'static', 'list' => 'array', 'class-string' => 'string', 'never' => 'never']
Properties
- $annotatedParameters : array<string|int, mixed>
- $caseCheck : int
- $checkedClasses : array<string|int, mixed>
- $classLoader : callable
- $darwinCache : array<string|int, mixed>
- $deprecated : array<string|int, mixed>
- $fileOffsets : array<string|int, mixed>
- $final : array<string|int, mixed>
- $finalMethods : array<string|int, mixed>
- $internal : array<string|int, mixed>
- $internalMethods : array<string|int, mixed>
- $isFinder : bool
- $loaded : array<string|int, mixed>
- $method : array<string|int, mixed>
- $methodTraits : array<string|int, mixed>
- $patchTypes : array<string|int, mixed>
- $returnTypes : array<string|int, mixed>
Methods
- __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
- 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
- parsePhpDoc() : array<string|int, mixed>
- patchMethod() : mixed
- Utility method to add @return annotations to the Symfony code-base where it triggers self-deprecations.
- patchReturnTypeWillChange() : mixed
- Utility method to add #[ReturnTypeWillChange] where php triggers deprecations.
- setReturnType() : void
Constants
BUILTIN_RETURN_TYPES
private
mixed
BUILTIN_RETURN_TYPES
= ['void' => true, 'array' => true, 'false' => true, 'bool' => true, 'callable' => true, 'float' => true, 'int' => true, 'iterable' => true, 'object' => true, 'string' => true, 'self' => true, 'parent' => true, 'mixed' => true, 'static' => true, 'null' => true, 'true' => true, 'never' => true]
MAGIC_METHODS
private
mixed
MAGIC_METHODS
= ['__isset' => 'bool', '__sleep' => 'array', '__toString' => 'string', '__debugInfo' => 'array', '__serialize' => 'array']
SPECIAL_RETURN_TYPES
private
mixed
SPECIAL_RETURN_TYPES
= ['void' => 'void', 'null' => 'null', 'resource' => 'resource', 'boolean' => 'bool', 'true' => 'true', 'false' => 'false', 'integer' => 'int', 'array' => 'array', 'bool' => 'bool', 'callable' => 'callable', 'float' => 'float', 'int' => 'int', 'iterable' => 'iterable', 'object' => 'object', 'string' => 'string', 'self' => 'self', 'parent' => 'parent', 'mixed' => 'mixed', 'static' => 'static', '$this' => 'static', 'list' => 'array', 'class-string' => 'string', 'never' => 'never']
Properties
$annotatedParameters
private
static array<string|int, mixed>
$annotatedParameters
= []
$caseCheck
private
static int
$caseCheck
$checkedClasses
private
static array<string|int, mixed>
$checkedClasses
= []
$classLoader
private
callable
$classLoader
$darwinCache
private
static array<string|int, mixed>
$darwinCache
= ['/' => ['/', []]]
$deprecated
private
static array<string|int, mixed>
$deprecated
= []
$fileOffsets
private
static array<string|int, mixed>
$fileOffsets
= []
$final
private
static array<string|int, mixed>
$final
= []
$finalMethods
private
static array<string|int, mixed>
$finalMethods
= []
$internal
private
static array<string|int, mixed>
$internal
= []
$internalMethods
private
static array<string|int, mixed>
$internalMethods
= []
$isFinder
private
bool
$isFinder
$loaded
private
array<string|int, mixed>
$loaded
= []
$method
private
static array<string|int, mixed>
$method
= []
$methodTraits
private
static array<string|int, mixed>
$methodTraits
= []
$patchTypes
private
array<string|int, mixed>
$patchTypes
= []
$returnTypes
private
static array<string|int, mixed>
$returnTypes
= []
Methods
__construct()
public
__construct(callable $classLoader) : mixed
Parameters
- $classLoader : callable
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>|nullcheckClasses()
public
static checkClasses() : bool
Return values
booldisable()
Disables the wrapping.
public
static disable() : void
enable()
Wraps all autoloaders.
public
static enable() : void
findFile()
public
findFile(string $class) : string|null
Parameters
- $class : string
Return values
string|nullgetClassLoader()
public
getClassLoader() : callable
Return values
callableloadClass()
Loads the given class or interface.
public
loadClass(string $class) : void
Parameters
- $class : string
Tags
checkClass()
private
checkClass(string $class[, string $file = null ]) : void
Parameters
- $class : string
- $file : string = null
darwinRealpath()
`realpath` on MacOSX doesn't normalize the case of characters.
private
darwinRealpath(string $real) : string
Parameters
- $real : string
Return values
stringfixReturnStatements()
private
fixReturnStatements(ReflectionMethod $method, string $returnType) : mixed
Parameters
- $method : ReflectionMethod
- $returnType : string
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, ReflectionType|null $returnType) : string
Parameters
- $type : string
- $class : string
- $parent : string|null
- $returnType : ReflectionType|null
Return values
stringparsePhpDoc()
private
parsePhpDoc(ReflectionClass|ReflectionMethod|ReflectionProperty $reflector) : array<string|int, mixed>
Parameters
- $reflector : ReflectionClass|ReflectionMethod|ReflectionProperty
Return values
array<string|int, mixed>patchMethod()
Utility method to add @return annotations to the Symfony code-base where it triggers self-deprecations.
private
patchMethod(ReflectionMethod $method, string $returnType, string $declaringFile, string $normalizedType) : mixed
Parameters
- $method : ReflectionMethod
- $returnType : string
- $declaringFile : string
- $normalizedType : string
patchReturnTypeWillChange()
Utility method to add #[ReturnTypeWillChange] where php triggers deprecations.
private
patchReturnTypeWillChange(ReflectionMethod $method) : mixed
Parameters
- $method : ReflectionMethod
setReturnType()
private
setReturnType(string $types, string $class, string $method, string $filename, string|null $parent[, ReflectionType $returnType = null ]) : void
Parameters
- $types : string
- $class : string
- $method : string
- $filename : string
- $parent : string|null
- $returnType : ReflectionType = null