Documentation

AttributeProcessor
in package
implements Middleware

Processes PHP 8 attributes on registered classes

Interfaces, Classes, Traits and Enums

Middleware

Table of Contents

$handlerClasses  : array<string|int, string>
$handlers  : array<string|int, array<string|int, AttributeHandler>>
$namespaces  : array<string|int, string>
add()  : mixed
Adds an attribute handler for processing
addNamespace()  : mixed
Adds a namespace
run()  : mixed
Creates the handlers then processes all interfaces in the App or those that are in the given namespaces.
createHandlersPerTarget()  : void
Creates the handler instances and puts them into the right `$handlers` array
isProcessAllowed()  : bool
If no namespace added returns true, otherwise checks the namespace and returns true if the interface is in it.
process()  : void
Processes one class with the given name
processAll()  : void
Processes all interfaces in the App or those that are in the given namespaces
processClass()  : void
Processes all class-level attributes for the class
processMethods()  : void
Processes all method-level attributes for all the methods of a class
processProperties()  : void
Processes all property-level attributes for all the properties of a class
processSubject()  : void
Processes attributes on a class, property or method

Properties

$handlers

protected array<string|int, array<string|int, AttributeHandler>> $handlers = [\Dynart\Micro\AttributeHandler::TARGET_CLASS => [], \Dynart\Micro\AttributeHandler::TARGET_PROPERTY => [], \Dynart\Micro\AttributeHandler::TARGET_METHOD => []]

Methods

add()

Adds an attribute handler for processing

public add(string $className) : mixed

The given class name should implement the AttributeHandler interface, otherwise it will throw a MicroException.

Parameters
$className : string

The class name

Tags
throws
MicroException

if the given class does not implement AttributeHandler

Return values
mixed

addNamespace()

Adds a namespace

public addNamespace(string $namespace) : mixed

If one or more namespace added only those will be processed. The namespace should NOT start with a backslash!

Parameters
$namespace : string
Return values
mixed

run()

Creates the handlers then processes all interfaces in the App or those that are in the given namespaces.

public run() : mixed
Return values
mixed

createHandlersPerTarget()

Creates the handler instances and puts them into the right `$handlers` array

protected createHandlersPerTarget() : void
Return values
void

isProcessAllowed()

If no namespace added returns true, otherwise checks the namespace and returns true if the interface is in it.

protected isProcessAllowed(string $className) : bool
Parameters
$className : string

The name of the class

Return values
bool

Should we process this class?

process()

Processes one class with the given name

protected process(string $className) : void
Parameters
$className : string

The name of the class

Return values
void

processAll()

Processes all interfaces in the App or those that are in the given namespaces

protected processAll() : void
Return values
void

processClass()

Processes all class-level attributes for the class

protected processClass(ReflectionClass $refClass) : void
Parameters
$refClass : ReflectionClass
Return values
void

processMethods()

Processes all method-level attributes for all the methods of a class

protected processMethods(ReflectionClass $refClass) : void
Parameters
$refClass : ReflectionClass
Return values
void

processProperties()

Processes all property-level attributes for all the properties of a class

protected processProperties(ReflectionClass $refClass) : void
Parameters
$refClass : ReflectionClass
Return values
void

processSubject()

Processes attributes on a class, property or method

protected processSubject(AttributeHandler $handler, string $className, ReflectionClass|ReflectionProperty|ReflectionMethod $subject) : void

Gets the PHP 8 attributes from the subject that match the handler's attribute class, instantiates each and calls the handler's handle() method.

Parameters
$handler : AttributeHandler

The attribute handler

$className : string

The class name

$subject : ReflectionClass|ReflectionProperty|ReflectionMethod

The reflection class, property or method

Return values
void

Search results