CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • AttributeResolver
      • ValueObject
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class Parser

Discover PHP attributes using tokenized declarations and reflection.

Namespace: Cake\AttributeResolver

Method Summary

  • __construct() public
  • extractAttributeArguments() protected

    Extract named arguments from a reflection attribute.

  • getAttributeConstructor() protected

    Get the constructor for an attribute class (cached).

  • getClassNamesFromTokens() protected

    Extract class name from PHP file using token parsing.

    Leverages PSR-4 constraint: one class per file. Returns immediately when the first class/interface/trait/enum is found.

  • getClassesFromFile() protected

    Extract class names from a PHP file.

    Uses token parsing to safely detect classes, interfaces, traits, and enums. Then loads them either via autoloader or direct file inclusion.

  • getDeclaringClassType() protected

    Detect declaring class kind from reflection.

  • getMethodVisibility() protected

    Detect method visibility from reflection metadata.

  • isAnonymousClass() protected

    Check if T_CLASS token represents an anonymous class.

    Anonymous classes are preceded by the 'new' keyword.

  • isTypeLoaded() protected

    Check if a type (class/interface/trait/enum) is already loaded.

  • loadType() protected

    Try to load a type via autoloader.

  • nextSignificantTokenId() protected

    Find the next token ID, skipping whitespace and comments.

  • parseAttributes() protected

    Parse reflection attributes and convert to AttributeInfo.

  • parseClass() protected

    Parse attributes from a class and its members.

  • parseConstant() protected

    Parse class constant attributes.

  • parseFile() public

    Parse a PHP file and extract all attributes.

  • parseMethod() protected

    Parse method attributes.

  • parseParameter() protected

    Parse parameter attributes.

  • parseProperty() protected

    Parse property attributes.

  • previousSignificantTokenId() protected

    Find the previous token ID, skipping whitespace and comments.

  • shouldExclude() protected

    Check if an attribute should be excluded.

Method Detail

__construct() ¶ public

__construct(array<string> $excludeAttributes = [])
Parameters
array<string> $excludeAttributes optional

extractAttributeArguments() ¶ protected

extractAttributeArguments(ReflectionAttribute<object> $attribute): array<string, mixed>

Extract named arguments from a reflection attribute.

Parameters
ReflectionAttribute<object> $attribute

Reflection attribute

Returns
array<string, mixed>

Named arguments array

getAttributeConstructor() ¶ protected

getAttributeConstructor(string $attributeName): ReflectionMethod|null

Get the constructor for an attribute class (cached).

Parameters
string $attributeName

Attribute class name

Returns
ReflectionMethod|null

Constructor or null if none exists

getClassNamesFromTokens() ¶ protected

getClassNamesFromTokens(string $filePath): array<string>

Extract class name from PHP file using token parsing.

Leverages PSR-4 constraint: one class per file. Returns immediately when the first class/interface/trait/enum is found.

Parameters
string $filePath

File path to parse

Returns
array<string>

Fully qualified class name (single element array)

getClassesFromFile() ¶ protected

getClassesFromFile(string $filePath): array<string>

Extract class names from a PHP file.

Uses token parsing to safely detect classes, interfaces, traits, and enums. Then loads them either via autoloader or direct file inclusion.

Parameters
string $filePath

File path (should be normalized with realpath)

Returns
array<string>

getDeclaringClassType() ¶ protected

getDeclaringClassType(ReflectionClass<object> $reflection): Cake\AttributeResolver\Enum\DeclaringClassType

Detect declaring class kind from reflection.

Parameters
ReflectionClass<object> $reflection

Class reflection

Returns
Cake\AttributeResolver\Enum\DeclaringClassType

getMethodVisibility() ¶ protected

getMethodVisibility(ReflectionMethod $method): Cake\AttributeResolver\Enum\MethodVisibility

Detect method visibility from reflection metadata.

Parameters
ReflectionMethod $method

Method reflection

Returns
Cake\AttributeResolver\Enum\MethodVisibility

isAnonymousClass() ¶ protected

isAnonymousClass(array<PhpToken> $tokens, int $currentIndex): bool

Check if T_CLASS token represents an anonymous class.

Anonymous classes are preceded by the 'new' keyword.

Parameters
array<PhpToken> $tokens

All tokens from PhpToken::tokenize()

int $currentIndex

Current token index

Returns
bool

True if anonymous class

isTypeLoaded() ¶ protected

isTypeLoaded(string $typeName): bool

Check if a type (class/interface/trait/enum) is already loaded.

Parameters
string $typeName

Type name to check

Returns
bool

True if type is loaded

loadType() ¶ protected

loadType(string $typeName): bool

Try to load a type via autoloader.

Parameters
string $typeName

Type name to load

Returns
bool

True if type was loaded

nextSignificantTokenId() ¶ protected

nextSignificantTokenId(array<PhpToken> $tokens, int $index): int|null

Find the next token ID, skipping whitespace and comments.

Parameters
array<PhpToken> $tokens

Tokens to inspect

int $index

Current token index

Returns
int|null

Significant token ID, or null at the end of the stream

parseAttributes() ¶ protected

parseAttributes(array<ReflectionAttribute<object>> $attributes, string $className, string $filePath, int $lineNumber, int $fileTime, Cake\AttributeResolver\ValueObject\AttributeTarget $target, string|null $pluginName): Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

Parse reflection attributes and convert to AttributeInfo.

Parameters
array<ReflectionAttribute<object>> $attributes

Reflection attributes

string $className

Class name

string $filePath

File path

int $lineNumber

Line number

int $fileTime

File modification time

Cake\AttributeResolver\ValueObject\AttributeTarget $target

Attribute target

string|null $pluginName

Plugin name

Returns
Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

parseClass() ¶ protected

parseClass(ReflectionClass<object> $reflection, string $filePath, int $fileTime, string|null $pluginName): Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

Parse attributes from a class and its members.

Parameters
ReflectionClass<object> $reflection

Class reflection

string $filePath

File path

int $fileTime

File modification time

string|null $pluginName

Plugin name

Returns
Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

parseConstant() ¶ protected

parseConstant(ReflectionClassConstant $constant, string $filePath, int $fileTime, string $className, bool $isDeclaringClassAbstract, Cake\AttributeResolver\Enum\DeclaringClassType $declaringClassType, string|null $pluginName): Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

Parse class constant attributes.

Parameters
ReflectionClassConstant $constant

Constant reflection

string $filePath

File path

int $fileTime

File modification time

string $className

Declaring class name

bool $isDeclaringClassAbstract

Whether the declaring class is abstract

Cake\AttributeResolver\Enum\DeclaringClassType $declaringClassType

Declaring class kind

string|null $pluginName

Plugin name

Returns
Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

parseFile() ¶ public

parseFile(SplFileInfo $file, string|null $pluginName = null): Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

Parse a PHP file and extract all attributes.

Parameters
SplFileInfo $file

File object to parse

string|null $pluginName optional

Plugin name if file belongs to a plugin

Returns
Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

parseMethod() ¶ protected

parseMethod(ReflectionMethod $method, string $filePath, int $fileTime, string $className, bool $isDeclaringClassAbstract, Cake\AttributeResolver\Enum\DeclaringClassType $declaringClassType, string|null $pluginName): Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

Parse method attributes.

Parameters
ReflectionMethod $method

Method reflection

string $filePath

File path

int $fileTime

File modification time

string $className

Declaring class name

bool $isDeclaringClassAbstract

Whether the declaring class is abstract

Cake\AttributeResolver\Enum\DeclaringClassType $declaringClassType

Declaring class kind

string|null $pluginName

Plugin name

Returns
Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

parseParameter() ¶ protected

parseParameter(ReflectionParameter $parameter, string $filePath, int $fileTime, string $className, string $methodName, bool $isDeclaringClassAbstract, Cake\AttributeResolver\Enum\DeclaringClassType $declaringClassType, Cake\AttributeResolver\Enum\MethodVisibility $methodVisibility, string|null $pluginName): Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

Parse parameter attributes.

Parameters
ReflectionParameter $parameter

Parameter reflection

string $filePath

File path

int $fileTime

File modification time

string $className

Declaring class name

string $methodName

Method name

bool $isDeclaringClassAbstract

Whether the declaring class is abstract

Cake\AttributeResolver\Enum\DeclaringClassType $declaringClassType

Declaring class kind

Cake\AttributeResolver\Enum\MethodVisibility $methodVisibility

Method visibility

string|null $pluginName

Plugin name

Returns
Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

parseProperty() ¶ protected

parseProperty(ReflectionProperty $property, string $filePath, int $fileTime, string $className, bool $isDeclaringClassAbstract, Cake\AttributeResolver\Enum\DeclaringClassType $declaringClassType, string|null $pluginName): Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

Parse property attributes.

Parameters
ReflectionProperty $property

Property reflection

string $filePath

File path

int $fileTime

File modification time

string $className

Declaring class name

bool $isDeclaringClassAbstract

Whether the declaring class is abstract

Cake\AttributeResolver\Enum\DeclaringClassType $declaringClassType

Declaring class kind

string|null $pluginName

Plugin name

Returns
Generator<Cake\AttributeResolver\ValueObject\AttributeInfo>

previousSignificantTokenId() ¶ protected

previousSignificantTokenId(array<PhpToken> $tokens, int $index): int|null

Find the previous token ID, skipping whitespace and comments.

Parameters
array<PhpToken> $tokens

Tokens to inspect

int $index

Current token index

Returns
int|null

Significant token ID, or null at the start of the stream

shouldExclude() ¶ protected

shouldExclude(string $attributeName): bool

Check if an attribute should be excluded.

Parameters
string $attributeName

Attribute name

Returns
bool

True if should be excluded

OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs