1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Add handler so closures can implement state renderable via the wrapper

This commit is contained in:
Aidan Woods 2019-01-20 02:13:20 +00:00
parent 1f06b47e6c
commit 23560bfa33
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

32
src/AST/Handler.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace Erusev\Parsedown\AST;
use Erusev\Parsedown\Html\Renderable;
use Erusev\Parsedown\State;
/**
* @template T as Renderable
*/
final class Handler implements StateRenderable
{
/** @var callable(State):T */
private $closure;
/**
* @param callable(State):T $closure
*/
public function __construct(callable $closure)
{
$this->closure = $closure;
}
/**
* @param State $State
* @return T&Renderable
*/
public function renderable(State $State)
{
return ($this->closure)($State);
}
}