PHP code example of ledc / macroable
1. Go to this page and download the library: Download ledc/macroable library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ledc / macroable example snippets
$macroableClass = new class() {
use Ledc\Macroable\Macroable;
};
$macroableClass::macro('concatenate', function(... $strings) {
return implode('-', $strings);
});
$macroableClass->concatenate('one', 'two', 'three'); // returns 'one-two-three'
$macroableClass = new class() {
protected $name = 'myName';
use Ledc\Macroable\Macroable;
};
$macroableClass::macro('getName', function() {
return $this->name;
};
$macroableClass->getName(); // returns 'myName'
$mixin = new class() {
public function mixinMethod()
{
return function() {
return 'mixinMethod';
};
}
public function anotherMixinMethod()
{
return function() {
return 'anotherMixinMethod';
};
}
};
$macroableClass->mixin($mixin);
$macroableClass->mixinMethod() // returns 'mixinMethod';
$macroableClass->anotherMixinMethod() // returns 'anotherMixinMethod';
use Ledc\Macroable\Macro;
use Ledc\Macroable\Macroable;
est
{
//use Macroable;
use Macro;
}
$ts = new Tests();
$ts->macro('hello', function () {
echo 'hello Tests' . PHP_EOL;
});
$ts->hello();
$req = new Request();
$req->macro('hello', function () {
echo 'hello Request' . PHP_EOL;
});
$req->hello();