PHP code example of nimbly / resolve
1. Go to this page and download the library: Download nimbly/resolve 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' );
nimbly / resolve example snippets
class Dispatcher
{
use Resolve ;
public function __construct (
protected Router $router,
protected ContainterInterface $container)
{
}
public function dispatch (ServerRequestInterface $request) : ResponseInterface
{
$route = $this ->router->resolve($request);
$handler = $this ->makeCallable($route->getHandler());
return $this ->call(
$handler,
$this ->container,
[ServerRequestInterface::class => $request]
);
}
}
$instance = $this ->make(
FooHandler::class,
$this ->container,
["additional_parameter" => "Foo" ]
);
$invokable = $this ->makeCallable(Foo::class, $this ->container);
$instance_method = $this ->makeCallable("\App\Http\Handlers\FooHandler@createNewFoo" );
$this ->call(
[new FooHandler, "findById" ],
$this ->container,
[
ServerRequestInteface::class => $serverRequest,
"id" => "3122accd-e640-4c4c-b299-ccad074cb077"
]
);
$this ->call(
[FooHandler::class, "findById" ],
$this ->container,
[
ServerRequestInteface::class => $serverRequest,
"id" => "3122accd-e640-4c4c-b299-ccad074cb077"
]
);
$this ->call(
new FooHandler,
$this ->container,
[
ServerRequestInteface::class => $serverRequest,
"id" => "3122accd-e640-4c4c-b299-ccad074cb077"
]
);
$this ->call(
"\Handlers\Foo\findById" ,
$this ->container,
[
ServerRequestInteface::class => $serverRequest,
"id" => "3122accd-e640-4c4c-b299-ccad074cb077"
]
);