Exemplo n.º 1
0
 public function testPassedRendererGetsContextObject()
 {
     $context = new AdhocContext();
     $renderer = $this->getMock(Renderer::class);
     $renderer->expects($this->at(0))->method('render')->with('inner_content', $context)->willReturn('the content');
     $renderer->expects($this->at(1))->method('render')->with('layout', $this->isInstanceOf(TwoStepContext::class))->willReturn('Final content');
     $twoStep = new TwoStepRenderer($renderer, 'layout');
     $this->assertSame('Final content', $twoStep->render('inner_content', $context));
 }
Exemplo n.º 2
0
<?php

require_once __DIR__ . '/000-example_functions.php';
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Cspray\Platelets\FileRenderer;
use Cspray\Platelets\TwoStepRenderer;
use Cspray\Platelets\AdhocContext;
use function Cspray\Platelets\Examples\stdout;
$fileRenderer = new FileRenderer(__DIR__ . '/templates');
$renderer = new TwoStepRenderer($fileRenderer, 'second_step_layout');
$data = ['dynamic' => 'dynamic'];
$output = $renderer->render('first_step_content', new AdhocContext($data));
stdout($output);
<?php

require_once __DIR__ . '/000-example_functions.php';
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Cspray\Platelets\FileRenderer;
use Cspray\Platelets\EventTriggeringRenderer;
use Cspray\Platelets\TwoStepRenderer;
use Cspray\Platelets\AdhocContext;
use Symfony\Component\EventDispatcher\EventDispatcher;
$fileRenderer = new FileRenderer(__DIR__ . '/templates');
$dispatcher = new EventDispatcher();
$eventRenderer = new EventTriggeringRenderer($fileRenderer, $dispatcher);
$renderer = new TwoStepRenderer($eventRenderer, 'second_step_layout');
$beforeCalled = 0;
$dispatcher->addListener($eventRenderer::BEFORE_RENDER_EVENT, function () use(&$beforeCalled) {
    $beforeCalled++;
    stdout('The before listener has been called ' . $beforeCalled . ' time(s)');
});
$afterCalled = 0;
$dispatcher->addListener($eventRenderer::AFTER_RENDER_EVENT, function () use(&$afterCalled) {
    $afterCalled++;
    stdout('The after listener has been called ' . $afterCalled . ' time(s)');
});
$output = $renderer->render('first_step_content', new AdhocContext(['dynamic' => 'dynamic']));
stdout($output);