Conversation
fd5a3f9 to
e68d789
Compare
e68d789 to
a555f74
Compare
1fa6b3a to
9f8b140
Compare
…o generate the artifact which reduces boilerplate code
The Attribute Resolver now follows CakePHP's pattern for static facade classes (Log, Cache, Configure), which don't dispatch events. This simplifies the implementation and aligns with framework conventions.
…cache over static cache in parser to mitagate potential leaks
9f8b140 to
8bcf96e
Compare
|
I think this is a great foundation for any future attribute based system we want to add to the framework 👍🏻 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 50 out of 50 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
If no further adjustments need to be made here this can be merged so our marathon runner @josbeir can continue his sprint towards attribute based routing 🏃🏻 |
|
|
This was actually already merged in #19171 as part of one of things needed for this PR
These are indeed ment to be used in userland to get information about attributes, not only core attributes but also custom attributes an app would implement.
This is exactly the reason why i made it as a Cache engine, can be easily adopted for future caching needs.
That's a though i also had. Its in
Great idea!
This was addressed in #19208 and got merged so this should be resolved :-) |
|
@jamisonbryant |
|
Before we merge: i still have a few open questions
|
For my attributes, I use the namespace
As someone who uses 'Resolver' a lot in their Cake codebase: yes, please. |
But the attribute resolver itself has multiple supporting classes, so having it under it's own namespace is fine. We could maybe in the future move it under
Using |
|
✔️ |
Refs #19167
Add Attribute Resolver Component
This PR introduces a new Attribute Resolver component that enables efficient discovery and querying of PHP 8 attributes across the codebase.
Overview
The Attribute Resolver provides a fluent interface for scanning source files, discovering attributes, and filtering them based on various criteria. It's designed to support runtime attribute discovery for features like auto-discovery of routes, commands, and other framework components.
Key Features
brick/varexporterto generate native PHP files optimized for OPcache - ideal for any long-running cache that prioritizes fast reads over fast writesArchitecture
brick/varexporterfor maximum performance with lazy hydration and O(1) indexes for fast filtering. Supports optional file validation to detect stale caches when source files are modified.AttributeInfoholds complete metadata about a discovered attribute.AttributeTargetdescribes what the attribute is attached to (class, method, property, etc).AttributeTargetTypeenum defines valid target types. All arereadonlyclasses that serialize automatically with PHP.Cache System
The resolver uses a high-performance caching system to store discovered attribute metadata for instant loading on subsequent requests. Instead of re-scanning and parsing files every time, the resolver simply reads from the cache.
PhpEngine (Recommended):
The default cache engine uses native PHP files generated with
brick/varexporterfor maximum performance. When combined with OPcache, this provides 145x faster warm cache lookups compared to cold scanning.PhpEngine is ideal for any long-running cache that prioritizes fast reads over fast writes. Once cached, subsequent reads are essentially "free" as PHP's OPcache keeps the compiled bytecode in memory. This makes it perfect for configuration data, route definitions, or any metadata that changes infrequently but is read constantly.
PhpEngine features:
Generic CacheEngine (Fallback):
When using other cache adapters (File, Redis, Memcached, etc.), with serialization enabled. While still performant, it's significantly slower than PhpEngine:
Cache Configuration:
The resolver uses a dedicated cache configuration
_cake_attributes_by default. For maximum performance, use the File adapter which enables PhpEngine:When
validateFilesis enabled, the cache checks each source file's modification time against the storedfileTime. If any source file is newer, the cache is considered stale and will be regenerated.Configuration
Configure the resolver with paths to scan and optional caching. Paths support glob/wildcard patterns and are automatically expanded against both the application root and all loaded plugin paths:
Usage Examples
CLI Commands
Three console commands are provided for managing and inspecting attributes:
Cache Warming:
List Attributes:
Inspect Details:
Performance
Benchmark Configuration:
Cache Performance:
Key Findings:
OPcache CLI Note: In CLI mode, OPcache only caches files from previous PHP processes. Run your application/commands twice after cache generation to see true warm OPcache performance.
Notes
Currently usesResolved in #19208Plugin::getCollection()to get active plugin paths which works but is not reliable when sharing the cache with CLI as the plugin list loaded in CLI is not the same as the one from HTTP.