1. Go to this page and download the library: Download divineniiquaye/php-invoker 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/ */
use ReflectionParameter;
use DivineNii\Invoker\Interfaces\ArgumentValueResolverInterface;
class MyParameterValueResolver implements ArgumentValueResolverInterface
{
/**
* {@inheritdoc}
*/
public function resolve(ReflectionParameter $parameter, array $providedParameters)
{
//....
}
}
use {ReflectionClass, ReflectionException};
use DivineNii\Invoker\Interfaces\ArgumentValueResolverInterface;
class MyParameterValueResolver implements ArgumentValueResolverInterface
{
/**
* {@inheritdoc}
*/
public function resolve(ReflectionParameter $parameter, array $providedParameters)
{
$parameterClass = $parameter->getClass();
if ($parameterClass instanceof ReflectionClass) {
try {
return $class->newInstance();
} catch (ReflectionExcetion $e) {
// ...
}
}
}
}
$invoker = new DivineNii\Invoker\Invoker([new MyParameterValueResolver()]);
$invoker->call(function (ArticleManager $articleManager) {
$articleManager->publishArticle('Hello world', 'This is the article content.');
});
$parameters = [];
// First parameter will receive "Welcome"
$parameters[] = 'Welcome';
// Parameter named "content" will receive "Hello world!"
$parameters['content'] = 'Hello world!';
// $published is not defined so it will use its default value
$invoker->call(function ($title, $content, $published = true) {
// ...
}, $parameters);
class MyHandler
{
public function __invoke()
{
// ...
}
}
// By default this work
$invoker->call('MyHandler');
// If we set up the container to use
$invoker = new Invoker\Invoker([], $container);
// Now 'MyHandler' parameters is resolved using the container if any!
$invoker->call('MyHandler');
class WelcomeController
{
public function home()
{
// ...
}
}
// By default this doesn't work: home() is not a static method
$invoker->call(['WelcomeController', 'home']);
// If we set up the container to use
$invoker = new Invoker\Invoker([], $container);
// Now 'WelcomeController' is resolved using the container!
$invoker->call(['WelcomeController', 'home']);
// Alternatively we can use the Class::method syntax
$invoker->call('WelcomeController::home');
bash
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.