gigaai / resolver
A Minimal PHP Resolver that Works!
Requires
- php: >=5.6
This package is auto-updated.
Last update: 2024-12-13 07:36:41 UTC
README
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.
Use cases:
Giga AI Framework
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
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). } }
Usage
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');