Renderer: Added shared data
parent
bcce2625a8
commit
e9f157ec5c
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Renderer;
|
||||
|
||||
abstract class Engine implements EngineInterface
|
||||
{
|
||||
/** @var array */
|
||||
protected $sharedData = [];
|
||||
|
||||
/**
|
||||
* @param mixed[]|string $key
|
||||
* @param null $value
|
||||
*/
|
||||
public function share($key, $value = null)
|
||||
{
|
||||
if (!is_array($key)) {
|
||||
$key = [$key => $value];
|
||||
}
|
||||
|
||||
$this->sharedData = array_replace_recursive($this->sharedData, $key);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Test\Unit\Renderer;
|
||||
|
||||
use Engelsystem\Test\Unit\Renderer\Stub\EngineImplementation;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class EngineTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Engelsystem\Renderer\Engine::share
|
||||
*/
|
||||
public function testShare()
|
||||
{
|
||||
$engine = new EngineImplementation();
|
||||
$engine->share(['foo' => ['bar' => 'baz', 'lorem' => 'ipsum']]);
|
||||
$engine->share(['foo' => ['lorem' => 'dolor']]);
|
||||
$engine->share('key', 'value');
|
||||
|
||||
$this->assertEquals(
|
||||
['foo' => ['bar' => 'baz', 'lorem' => 'dolor'], 'key' => 'value'],
|
||||
$engine->getSharedData()
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Test\Unit\Renderer\Stub;
|
||||
|
||||
use Engelsystem\Renderer\Engine;
|
||||
|
||||
class EngineImplementation extends Engine
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get(string $path, array $data = []): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function canRender(string $path): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSharedData(): array
|
||||
{
|
||||
return $this->sharedData;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue