1. Go to this page and download the library: Download crysalead/filter 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/ */
crysalead / filter example snippets
class Home
{
public static function version()
{
return '1.0.0';
}
public function enter($name)
{
return "Welcome {$name}!";
}
}
namespace City;
use Lead\Filter\Filters;
class Home {
public static function version()
{
Filters::run(get_called_class(), __FUNCTION__, [], function($next) {
return '1.0.0'; // Your inchanged code here
});
}
public function enter($name)
{
Filters::run($this, __FUNCTION__, [$name], function($next, $name) {
return "Welcome {$name}!"; // Your inchanged code here
});
}
}
use Lead\Filter\Filters;
Filters::apply('city\Home', 'version', function($next) {
$version = $next();
return "Version: {$version}";
});
$home = new Home();
Filters::apply($home, 'enter', function($next, $name) {
$name = "Mister {$name}";
return $next($name);
});
echo "You are using the Home " . Home::version();
echo $home->enter('Bob');