Skip to content

Instantly share code, notes, and snippets.

@MugeSo
Created July 20, 2012 03:58
Show Gist options
  • Save MugeSo/3148548 to your computer and use it in GitHub Desktop.
Save MugeSo/3148548 to your computer and use it in GitHub Desktop.
Render a view without asking.
<?php
interface HearerInterface
{
public function retain($key, $value);
}
interface SelfExpressableInteface
{
public function expressSelf(HearerInteface $hearer);
}
class Renderer implements HearerInterface
{
public function render()
{
/* render */
}
/* other implementation */
}
class SomeModel implements SelfExpressableInterface
{
private $_name;
public function __construct($name)
{
$this->_name = $name;
}
public function expressSelf(HearerInteface $hearer)
{
$hearer->retain('some.identifier.name', $this->_name);
}
}
$renderer = new Renderer();
$model = new SomeModel('hoge');
$model->expressSelf($renderer);
$renderer->render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment