Wallogit.com
2017 © Pedro Peláez
A Minimal PHP Resolver that Works!
A Minimal PHP Resolver That Works!, (*1)
Resolver makes your code easier to read, remember and use. This standalone library is minimal & fast (~1.3KB) which you can use in any project, it uses PHP ReflectionMethod and ReflectionFunction feature., (*2)
Giga AI framework uses resolver to help people define callback for a node easier. You don't need to remember the position of $bot, $lead and $input variable, you can use only variable you need. The callback is flexible, backward compatibility because we can add more variable later., (*3)
$bot->answers('email', function ($bot, $lead, $input) {
//
});
LightKit uses resolver to let people define their controllers with Laravel syntax., (*4)
<?php
class SettingController extends Controller
{
public function index()
{
// Method that doesn't have any argument.
}
public function create($request)
{
// Method that take $request argument
}
public function update($id, $request)
{
// $request argument can be in any position (in this case, second).
}
}
Resolve steps is easy: create an instance, bind data and resolve. 0. First, like other repo, you still need to composer require:, (*5)
composer require gigaai/resolver
Then you need to require 'vendor/autoload.php', (*6)
Create $resolver instance, (*7)
$resolver = new GigaAI\Resolver\Resolver;
$resolver->bind([
'id' => 1,
'request' => $_REQUEST
])->resolve([$class, 'method']);
// or
$resolver->bind([
'id' => 1,
'request' => $_REQUEST
])->resolve('function_name');