class ClassLoader (View source)

Class Loader implementation for test classes.

Constants

MAPPING_TYPE_PSR0

MAPPING_TYPE_PSR4

MAPPING_TYPE_CLASSMAP

MAPPING_TYPE_FILES

Properties

protected array $packageNamespaces

A list of namespaces this class loader is definitely responsible for.

protected bool $considerTestsNamespace
protected array $ignoredClassNames
protected array $fallbackClassPaths
protected array $nonExistentClasses

Cache classNames that were not found in this class loader in order to save time in resolving those non existent classes.

Methods

__construct(array $defaultPackageEntries = [])

No description

bool
loadClass(string $className)

Loads php files containing classes or interfaces found in the classes directory of a package and specifically registered classes.

bool
loadClassFromPossiblePaths(array $possiblePaths, array $namespaceParts, int $packageNamespacePartCount)

Tries to load a class from a list of possible paths. This is needed because packages are not prefix-free; i.e.

void
setPackages(array $activePackages)

Sets the available packages

void
createNamespaceMapEntry(string $namespace, string $classPath, string $mappingType = self::MAPPING_TYPE_PSR0)

Add a namespace to class path mapping to the class loader for resolving classes.

void
createFallbackPathEntry(string $path)

Adds an entry to the fallback path map. MappingType for this kind of paths is always PSR4 as no package namespace is used then.

void
removeNamespaceMapEntry(string $namespace, string $classPath, string $mappingType = self::MAPPING_TYPE_PSR0)

Tries to remove a possibly existing namespace to class path map entry.

string
buildClassPathWithPsr0(array $classNameParts, string $classPath)

Try to build a path to a class according to PSR-0 rules.

string
buildClassPathWithPsr4(array $classNameParts, string $classPath, int $packageNamespacePartCount)

Try to build a path to a class according to PSR-4 rules.

void
setConsiderTestsNamespace(bool $flag)

Sets the flag which enables or disables autoloading support for functional test files.

static bool
isAutoloadTypeWithPredictableClassPath(string $mappingType)

Is the given mapping type predictable in terms of path to class name

Details

__construct(array $defaultPackageEntries = [])

No description

Parameters

array $defaultPackageEntries

Adds default entries for packages that should be available for very early loading

bool loadClass(string $className)

Loads php files containing classes or interfaces found in the classes directory of a package and specifically registered classes.

Parameters

string $className

Name of the class/interface to load

Return Value

bool

protected bool loadClassFromPossiblePaths(array $possiblePaths, array $namespaceParts, int $packageNamespacePartCount)

Tries to load a class from a list of possible paths. This is needed because packages are not prefix-free; i.e.

there may exist a package "Neos" and a package "Neos.NodeTypes" -- so a class Neos\NodeTypes\Foo must be first loaded (if it exists) from Neos.NodeTypes, falling back to Neos afterwards.

Parameters

array $possiblePaths
array $namespaceParts
int $packageNamespacePartCount

Return Value

bool

void setPackages(array $activePackages)

Sets the available packages

Parameters

array $activePackages

An array of \Neos\Flow\Package\Package objects

Return Value

void

protected void createNamespaceMapEntry(string $namespace, string $classPath, string $mappingType = self::MAPPING_TYPE_PSR0)

Add a namespace to class path mapping to the class loader for resolving classes.

Parameters

string $namespace

A namespace to map to a class path.

string $classPath

The class path to be mapped.

string $mappingType

The mapping type for this mapping entry. Currently one of self::MAPPING_TYPE_PSR0 or self::MAPPING_TYPE_PSR4 will work. Defaults to self::MAPPING_TYPE_PSR0

Return Value

void

void createFallbackPathEntry(string $path)

Adds an entry to the fallback path map. MappingType for this kind of paths is always PSR4 as no package namespace is used then.

Parameters

string $path

The fallback path to search in.

Return Value

void

protected void removeNamespaceMapEntry(string $namespace, string $classPath, string $mappingType = self::MAPPING_TYPE_PSR0)

Tries to remove a possibly existing namespace to class path map entry.

Parameters

string $namespace

A namespace mapped to a class path.

string $classPath

The class path to be removed.

string $mappingType

The mapping type for this mapping entry. Currently one of self::MAPPING_TYPE_PSR0 or self::MAPPING_TYPE_PSR4 will work. Defaults to self::MAPPING_TYPE_PSR0

Return Value

void

protected string buildClassPathWithPsr0(array $classNameParts, string $classPath)

Try to build a path to a class according to PSR-0 rules.

Parameters

array $classNameParts

Parts of the FQ classname.

string $classPath

Already detected class path to a possible package.

Return Value

string

protected string buildClassPathWithPsr4(array $classNameParts, string $classPath, int $packageNamespacePartCount)

Try to build a path to a class according to PSR-4 rules.

Parameters

array $classNameParts

Parts of the FQ classname.

string $classPath

Already detected class path to a possible package.

int $packageNamespacePartCount

Amount of parts of the className that is also part of the package namespace.

Return Value

string

void setConsiderTestsNamespace(bool $flag)

Sets the flag which enables or disables autoloading support for functional test files.

Parameters

bool $flag

Return Value

void

static bool isAutoloadTypeWithPredictableClassPath(string $mappingType)

Is the given mapping type predictable in terms of path to class name

Parameters

string $mappingType

Return Value

bool