class ClassManifest (View source)

A utility class which builds a manifest of all classes, interfaces and caches it.

It finds the following information:

  • Class and interface names and paths.
  • All direct and indirect descendants of a class.
  • All implementors of an interface.

To be consistent; In general all array keys are lowercase, and array values are correct-case

Properties

protected string $base

base manifest directory

protected CacheFactory $cacheFactory

Used to build cache during boot

protected CacheInterface|null $cache

Cache to use, if caching.

protected string $cacheKey

Key to use for the top level cache of all items

protected array $serialisedProperties

Array of properties to cache

protected array $classes

Map of lowercase class names to paths

protected array $classNames

Map of lowercase class names to case-correct names

protected array $roots

List of root classes with no parent class Keys are lowercase, values are correct case.

protected array $children

List of direct children for any class.

protected array $descendants

List of descendents for any class (direct + indirect children) Keys are lowercase, values are arrays.

protected array $interfaces

Map of lowercase interface name to path those files

protected array $interfaceNames

Map of lowercase interface name to proper case

protected array $implementors

List of direct implementors of any interface Keys are lowercase, values are arrays.

protected array $traits

Map of lowercase trait names to paths

protected array $traitNames

Map of lowercase trait names to proper case

protected array $enums

Map of lowercase enum names to paths

protected array $enumNames

Map of lowercase enum names to proper case

Methods

public
__construct(string $base, CacheFactory $cacheFactory = null)

Constructs and initialises a new class manifest, either loading the data from the cache or re-scanning for classes.

public
init(bool $includeTests = false, bool $forceRegen = false)

Initialise the class manifest

public
Parser
getParser()

Get or create active parser

public
NodeTraverser
getTraverser()

Get node traverser for parsing class files

public
getVisitor()

Get visitor for parsing class files

public
string|null
getItemPath(string $name)

Returns the file path to a class or interface if it exists in the manifest.

public
string
getItemName(string $name)

Return correct case name

public
array
getClasses()

Returns a map of lowercased class names to file paths.

public
array
getClassNames()

Returns a map of lowercase class names to proper class names in the manifest

public
array
getTraits()

Returns a map of lowercased trait names to file paths.

public
array
getTraitNames()

Returns a map of lowercase trait names to proper trait names in the manifest

public
array
getEnums()

Returns a map of lowercased enum names to file paths.

public
array
getEnumNames()

Returns a map of lowercase enum names to proper enum names in the manifest

public
array
getDescendants()

Returns an array of all the descendant data.

public
array
getDescendantsOf(string|object $class)

Returns an array containing all the descendants (direct and indirect) of a class.

public
array
getInterfaces()

Returns a map of lowercased interface names to file locations.

public
array
getInterfaceNames()

Return map of lowercase interface names to proper case names in the manifest

public
array
getImplementors()

Returns a map of lowercased interface names to the classes the implement them.

public
array
getImplementorsOf(string $interface)

Returns an array containing the class names that implement a certain interface.

public
getOwnerModule(string $class)

Get module that owns this class

public
regenerate(bool $includeTests)

Completely regenerates the manifest file.

public
handleFile(string $basename, string $pathname, bool $includeTests)

Visit a file to inspect for classes, interfaces and traits

protected
array
coalesceDescendants(string $class)

Recursively coalesces direct child information into full descendant information.

protected
bool
loadState(array $data)

Reload state from given cache data

protected
array
getState()

Load current state into an array of data

protected
bool
validateItemCache(array $data)

Verify that cached data is valid for a single item

Details

__construct(string $base, CacheFactory $cacheFactory = null)

Constructs and initialises a new class manifest, either loading the data from the cache or re-scanning for classes.

Parameters

string $base

The manifest base path.

CacheFactory $cacheFactory

Optional cache to use. Set to null to not cache.

init(bool $includeTests = false, bool $forceRegen = false)

Initialise the class manifest

Parameters

bool $includeTests
bool $forceRegen

Parser getParser()

Get or create active parser

Return Value

Parser

NodeTraverser getTraverser()

Get node traverser for parsing class files

Return Value

NodeTraverser

ClassManifestVisitor getVisitor()

Get visitor for parsing class files

Return Value

ClassManifestVisitor

string|null getItemPath(string $name)

Returns the file path to a class or interface if it exists in the manifest.

Parameters

string $name

Return Value

string|null

string getItemName(string $name)

Return correct case name

Parameters

string $name

Return Value

string

Correct case name

array getClasses()

Returns a map of lowercased class names to file paths.

Return Value

array

array getClassNames()

Returns a map of lowercase class names to proper class names in the manifest

Return Value

array

array getTraits()

Returns a map of lowercased trait names to file paths.

Return Value

array

array getTraitNames()

Returns a map of lowercase trait names to proper trait names in the manifest

Return Value

array

array getEnums()

Returns a map of lowercased enum names to file paths.

Return Value

array

array getEnumNames()

Returns a map of lowercase enum names to proper enum names in the manifest

Return Value

array

array getDescendants()

Returns an array of all the descendant data.

Return Value

array

array getDescendantsOf(string|object $class)

Returns an array containing all the descendants (direct and indirect) of a class.

Parameters

string|object $class

Return Value

array

array getInterfaces()

Returns a map of lowercased interface names to file locations.

Return Value

array

array getInterfaceNames()

Return map of lowercase interface names to proper case names in the manifest

Return Value

array

array getImplementors()

Returns a map of lowercased interface names to the classes the implement them.

Return Value

array

array getImplementorsOf(string $interface)

Returns an array containing the class names that implement a certain interface.

Parameters

string $interface

Return Value

array

Module getOwnerModule(string $class)

Get module that owns this class

Parameters

string $class

Class name

Return Value

Module

regenerate(bool $includeTests)

Completely regenerates the manifest file.

Parameters

bool $includeTests

handleFile(string $basename, string $pathname, bool $includeTests)

Visit a file to inspect for classes, interfaces and traits

Parameters

string $basename
string $pathname
bool $includeTests

Exceptions

Exception

protected array coalesceDescendants(string $class)

Recursively coalesces direct child information into full descendant information.

Parameters

string $class

Return Value

array

protected bool loadState(array $data)

Reload state from given cache data

Parameters

array $data

Return Value

bool

True if cache was valid and successfully loaded

protected array getState()

Load current state into an array of data

Return Value

array

protected bool validateItemCache(array $data)

Verify that cached data is valid for a single item

Parameters

array $data

Return Value

bool