-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First implementation of database queries
- Loading branch information
Showing
3 changed files
with
348 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
/** | ||
* * Created by mtils on 28.03.20 at 07:51. | ||
**/ | ||
|
||
namespace Ems\Core\Support; | ||
|
||
use Ems\Contracts\Core\Renderable; | ||
use Ems\Contracts\Core\Renderer; | ||
use Ems\Contracts\Core\Stringable; | ||
|
||
use function call_user_func; | ||
|
||
/** | ||
* Class GenericRenderer | ||
* | ||
* This is a helper to create a renderer on the fly. | ||
* | ||
* @package Ems\Core\Support | ||
*/ | ||
class GenericRenderer implements Renderer | ||
{ | ||
/** | ||
* @var callable | ||
*/ | ||
private $canRenderCallable; | ||
|
||
/** | ||
* @var callable | ||
*/ | ||
private $renderCallable; | ||
|
||
/** | ||
* GenericRenderer constructor. | ||
* | ||
* @param callable $renderCallable | ||
* @param callable $canRenderCallable (optional) | ||
*/ | ||
public function __construct(callable $renderCallable, callable $canRenderCallable = null) | ||
{ | ||
$this->renderCallable = $renderCallable; | ||
$this->canRenderCallable = $canRenderCallable ?: function () { | ||
return true; | ||
}; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param Renderable | ||
* | ||
* @return bool | ||
**/ | ||
public function canRender(Renderable $item) | ||
{ | ||
return call_user_func($this->canRenderCallable, $item); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param Renderable $item | ||
* | ||
* @return string|Stringable | ||
**/ | ||
public function render(Renderable $item) | ||
{ | ||
return call_user_func($this->renderCallable, $item); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters