fyre / macro
A macro utility library.
Installs: 1 321
Dependents: 48
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/fyre/macro
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
Macros
You can attach the Fyre\Utility\Traits\MacroTrait
to any class.
use Fyre\Utility\Traits\MacroTrait; // in any class class MyClass { use MacroTrait; }
Clear Macros
Clear all macros.
MyClass::clearMacros();
Has Macro
Determine whether a macro is registered.
$name
is a string representing the name of the macro.
$hasMacro = MyClass::hasMacro($name);
Macro
Register a macro.
$name
is a string representing the name of the macro.$callback
is the macro callback.
MyClass::macro($name, $callback);
Calling Macros
MyClass::macro('myMethod', function(): bool { return true; }); new MyClass()->myMethod(); // true
Static Macros
You can attach the Fyre\Utility\Traits\StaticMacroTrait
to any class.
use Fyre\Utility\Traits\StaticMacroTrait; // in any class class MyClass { use StaticMacroTrait; }
Clear Static Macros
Clear all static macros.
MyClass::clearStaticMacros();
Has Static Macro
Determine whether a static macro is registered.
$name
is a string representing the name of the macro.
$hasStaticMacro = MyClass::hasStaticMacro($name);
Static Macro
Register a static macro.
$name
is a string representing the name of the macro.$callback
is the macro callback.
MyClass::staticMacro($name, $callback);
Calling Static Macros
MyClass::staticMacro('myMethod', function(): bool { return true; }); MyClass::myMethod(); // true