About
This is a library that can be used to call functions, closures(AKA: anonymous functions), classes and methods. It can be used for calling dynamic values, say a handler in an HTTP router. Or containers.
Installation
You can install this via composer, or manually download the files.
composer require fobber/caller
Caller Documentation
\Fobber\Caller\Caller::callClosure(
\Closure $closure,
array $parameters = []
);
\Fobber\Caller\Caller::callFunction(
string $function,
array $parameters = []
);
\Fobber\Caller\Caller::callClass(
string $class,
array $parameters = []
);
\Fobber\Caller\Caller::callMethod(
object $object,
string $method,
array $parameters = [],
bool $static_only = false
);Caller Basic Usage
require_once __DIR__.'/path/to/autoload.php';
use \Fobber\Caller\{
Validator,
Caller
};
use \Fobber\Exceptions\{
InvalidFunctionException,
InvalidClassException,
InvalidMethodException
};
$validator = new Validator;
$caller = new Caller($validator);Calling Closures
$value = $caller->…Hey! I published my first library to composer. Any PHP developers have time to read some code, you can check out my package on GitHub/Packagist.
If you read the code, it'd be nice if you'd let me know what you think.
You can install it via Composer, like so:
composer require fobber/caller
It's a library for calling things like functions, closures, classes and methods. You might be wondering why I would make something like this, but I made it so you can utilize it to make calls to dynamic values/handlers. Let's say you're building a Router library. And you want to able to separate your code into different files, like Controllers.
So you could so something similar to:
$object = $caller->callClass(IndexController::class);
$method = '__invoke';
$parameters = [$request, $response];
$caller->callMethod($object, $method, $parameters);
Or later once I got it implemented:
$caller->call('IndexController', [$request, $response]);
And with a neat little feature, you can have prefix and suffix parameters. If say all your controllers and their methods need a $request and $response, you can set it. And all you have to do is this:
$caller->call('IndexController');