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
- 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']
- $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
- 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 mixed
$annotatedParameters
= []
$caseCheck
private
static mixed
$caseCheck
$checkedClasses
private
static mixed
$checkedClasses
= []
$classLoader
private
mixed
$classLoader
$darwinCache
private
static mixed
$darwinCache
= ['/' => ['/', []]]
$deprecated
private
static mixed
$deprecated
= []
$fileOffsets
private
static mixed
$fileOffsets
= []
$final
private
static mixed
$final
= []
$finalMethods
private
static mixed
$finalMethods
= []
$internal
private
static mixed
$internal
= []
$internalMethods
private
static mixed
$internalMethods
= []
$isFinder
private
mixed
$isFinder
$loaded
private
mixed
$loaded
= []
$method
private
static mixed
$method
= []
$methodTraits
private
static mixed
$methodTraits
= []
$patchTypes
private
mixed
$patchTypes
$returnTypes
private
static mixed
$returnTypes
= []
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()
public
getClassLoader() : callable
Return values
callable —loadClass()
Loads the given class or interface.
public
loadClass(string $class) : void
Parameters
- $class : string
Tags
Return values
void —checkClass()
private
checkClass(string $class[, string|null $file = null ]) : void
Parameters
- $class : string
- $file : string|null = 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, ReflectionType|null $returnType) : string
Parameters
- $type : string
- $class : string
- $parent : string|null
- $returnType : ReflectionType|null
Return values
string —parsePhpDoc()
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
Return values
mixed —patchReturnTypeWillChange()
Utility method to add #[ReturnTypeWillChange] where php triggers deprecations.
private
patchReturnTypeWillChange(ReflectionMethod $method) : mixed
Parameters
- $method : ReflectionMethod
Return values
mixed —setReturnType()
private
setReturnType(string $types, string $class, string $method, string $filename, string|null $parent[, ReflectionType|null $returnType = null ]) : void
Parameters
- $types : string
- $class : string
- $method : string
- $filename : string
- $parent : string|null
- $returnType : ReflectionType|null = null