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:
parent
1f06b47e6c
commit
23560bfa33
32
src/AST/Handler.php
Normal file
32
src/AST/Handler.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user