fyre / macro
A macro utility library.
v1.0
2025-07-27 11:31 UTC
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^12
README
FyreMacro is a free, open-source macro utility library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/macro
In PHP:
use Fyre\Utility\Traits\MacroTrait; // in any class class MyClass { use MacroTrait; }
Methods
Clear Macros
Clear all macros.
MyClass::clearMacros();
Has Macro
Determine whether a macro is registered.
$hasMacro = MyClass::hasMacro($name);
Macro
Register a macro.
$name
is a string representing the name of the callback.$callback
is the macro callback.
MyClass::macro($name, $callback);
Calling Macros
Static Macros
MyClass::macro('myMethod', function(): bool { return true; }); MyClass::myMethod(); // true
Instance Macros
MyClass::macro('myMethod', function(): bool { return $this->value; }); $obj = new MyClass(); $obj->value = true; $obj->myMethod(); // true