PHP code example of istianxin / decorator-laravel
1. Go to this page and download the library: Download istianxin/decorator-laravel 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/ */
istianxin / decorator-laravel example snippets
class MultiplicationMiddleware
{
public function handle($data, $next, $factor = 1)
{
return $next($data) * $factor;
}
}
call_user_func_array()
$class = new class {
public function add($a, $b)
{
return $a + $b;
}
};
$a = 1;
$b = 2;
$factor = 3;
$decorator = new Decorator();
// classname with parameter
$middleware = MultiplicationMiddleware::class . ':' . $factor;
$result = $decorator->setCallback([$class, 'add'])
->setMiddleware($middleware)
->setParameters([$a, $b])
->decorate();
echo $result; // 9