Download the PHP package bermudaphp/reflection without Composer
On this page you can find all versions of the php package bermudaphp/reflection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bermudaphp/reflection
More information about bermudaphp/reflection
Files in bermudaphp/reflection
Package reflection
Short Description Powerful PHP reflection utility with caching and advanced metadata handling
License MIT
Informations about the package reflection
Bermuda Reflection
Русская версия
A powerful static utility class for PHP reflection operations with built-in caching and advanced metadata (attributes) handling. Provides convenient methods for working with PHP 8+ attributes and reflection objects.
Features
- 🚀 Performance Optimized: Built-in caching for reflection objects
- 🎯 Attribute Support: Comprehensive PHP 8+ attributes handling
- 🔍 Deep Search: Search attributes in class members (methods, properties, constants)
- 🧩 Universal Reflection: Smart reflection creation from various data types
- 💾 Memory Efficient: Automatic caching prevents duplicate reflection objects
- 🔧 Type Safe: Full generic type support for attributes
Installation
Requirements
- PHP 8.4 or higher
Quick Start
Basic Attribute Retrieval
Universal Reflection
Advanced Features
Deep Attribute Search
Search for attributes not only on the class itself, but also on all its members:
Path Format for Deep Search
Deep search results use descriptive paths to identify where attributes were found:
ClassName- Attribute on the class itselfClassName::methodName- Attribute on a methodClassName::$propertyName- Attribute on a propertyClassName::CONSTANT_NAME- Attribute on a class constant
Reflection Caching
The class automatically caches reflection objects for improved performance:
API Reference
Metadata Methods
getMetadata()
Retrieves all attributes from a reflection object. Optionally filter by attribute class name.
getFirstMetadata()
Gets the first attribute instance of the specified type.
hasMetadata()
Checks if the reflection object has any attributes of the specified type.
Deep Search Methods
getDeepMetadata()
Searches for attributes in the class and all its members (methods, properties, constants).
getFirstDeepMetadata()
Gets the first attribute instance found anywhere in the class.
hasDeepMetadata()
Checks if the class or any of its members have the specified attribute.
Reflection Creation Methods
reflect()
Universal reflection method that automatically determines the appropriate reflection type.
callable()
Creates reflection for callable types (functions, methods, closures).
object()
Creates cached ReflectionObject for the given object instance.
class()
Creates cached ReflectionClass for the given class name. Returns null if class doesn't exist.
Real-World Examples
Dependency Injection Container
Route Discovery
Validation with Attributes
Event Handler Discovery
Performance Tips
- Leverage Caching: The class automatically caches reflection objects, so prefer using static methods over creating new reflections manually
- Use Specific Searches: When searching for specific attribute types, pass the class name to avoid unnecessary processing
- Deep Search Wisely: Use deep search only when you need to search in class members, as it's more expensive than regular metadata retrieval
- Batch Operations: When working with multiple classes, the caching system provides significant performance benefits
License
This project is licensed under the MIT License - see the LICENSE file for details.