A Minimal PHP Resolver That Works!
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.
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.
$bot->answers('email', function ($bot, $lead, $input) {
//
});
LightKit uses resolver to let people define their controllers with Laravel syntax.
<?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:
composer require gigaai/resolver
-
Then you need to
require 'vendor/autoload.php'
-
Create
$resolver
instance
$resolver = new GigaAI\Resolver\Resolver;
- Bind [data] and resolve [method or function]
$resolver->bind([
'id' => 1,
'request' => $_REQUEST
])->resolve([$class, 'method']);
// or
$resolver->bind([
'id' => 1,
'request' => $_REQUEST
])->resolve('function_name');