Download the PHP package theflowbyte/laravel-macro-attribute without Composer
On this page you can find all versions of the php package theflowbyte/laravel-macro-attribute. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download theflowbyte/laravel-macro-attribute
More information about theflowbyte/laravel-macro-attribute
Files in theflowbyte/laravel-macro-attribute
Package laravel-macro-attribute
Short Description Simplifies binding macros to methods in Laravel using PHP 8 attributes.
License MIT
Informations about the package laravel-macro-attribute
Laravel Macro Attribute
Laravel Macro Attribute simplifies binding macros to methods in Laravel using PHP 8 attributes. Define macros with the #[Macro]
attribute, and they are registered for one or more target classes.
Features
- Simple Macro Registration: Bind macros to one or multiple Laravel classes like
Collection
,Request
, and others. - Powered by PHP 8 Attributes: Clean and modern approach with minimal boilerplate.
- Custom Macro Names: Use the default method name or specify custom macro names.
- Support for Multiple Classes: A single macro can be registered for multiple target classes.
Installation
Require the package via Composer:
Usage
Step 1: Define Macros with the #[Macro]
Attribute
Create a class with static methods and use the #[Macro]
attribute to bind them to one or more target classes.
Step 2: Register Classes with the #[Macro]
Attribute
Register the classes containing the macros using MacroAttributeBinder:
Step 3: Use the Macros
Once registered, the macros are available on the target classes:
Advanced Features
Support for Multiple Target Classes
You can bind a single macro to multiple target classes by passing an array of class names to the targetClass parameter:
TODO
Features to Implement
- Code Generator for IDE Autocomplete
- Create a standalone repository for a tool that generates PHPDoc annotations for registered macros.
- Enhance IDE support for Laravel macros, providing autocomplete in PHPStorm, VSCode, etc.
Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.
License
The MIT License (MIT).