Skip to content

Commit

Permalink
Merge pull request #13 from koriym/meta
Browse files Browse the repository at this point in the history
assign _code and _headers meta information in default
  • Loading branch information
koriym committed Aug 20, 2015
2 parents 990bc93 + 0c10b89 commit 4776d0b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/TwigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public function render(ResourceObject $ro)
}
throw new Exception\TemplateNotFound($e->getMessage(), 500, $e);
}
$ro->view = $template->render($ro->body);
$body = is_array($ro->body) ? $ro->body : [];
$body += ['_code' => $ro->code, '_headers' => $ro->headers];
$ro->view = $template->render($body);

return $ro->view;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Resource/Page/Code.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
code:{{ _code }} date:{{ _headers['Last-Modified'] }}
16 changes: 16 additions & 0 deletions tests/Resource/Page/Code.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Madapaja\TwigModule\Resource\Page;

use BEAR\Resource\ResourceObject;

class Code extends ResourceObject
{
public function onGet()
{
$this->code = 200;
$this->headers['Last-Modified'] = 'Tue, 15 Nov 1994 12:45:26 GMT';

return $this;
}
}
7 changes: 7 additions & 0 deletions tests/Resource/Page/FileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public function testPage()
$this->assertSame('<!DOCTYPE html><html><head><title>Page</title><body>Hello, BEAR.Sunday!</body></html>', (string) $ro->onGet());
}

public function testCode()
{
$ro = $this->injector->getInstance(\Madapaja\TwigModule\Resource\Page\Code::class);

$this->assertSame('code:200 date:Tue, 15 Nov 1994 12:45:26 GMT', (string) $ro->onGet());
}

public function testIndexTemplateWithoutPaths()
{
$injector = new Injector(new TwigFileLoaderTestModule([]));
Expand Down

0 comments on commit 4776d0b

Please sign in to comment.