Created
July 30, 2012 13:45
-
-
Save vicb/3207019 to your computer and use it in GitHub Desktop.
Twig issue 792
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
<?php | |
// Update with your local path to the autoloader | |
require_once '../vendor/twig/twig/lib/Twig/Autoloader.php'; | |
Twig_Autoloader::register(); | |
$loader = new Twig_Loader_String(); | |
$twig = new Twig_Environment($loader); | |
class TwigTest implements \ArrayAccess | |
{ | |
public $vars; | |
private $data; | |
public function __construct() | |
{ | |
$this->vars = "Pass !"; | |
$this->data = array('bar' => 1); | |
} | |
public function offsetExists($offset) | |
{ | |
return array_key_exists($offset, $this->data); | |
} | |
public function offsetGet($offset) | |
{ | |
if (!$this->offsetExists($offset)) { | |
throw new \RuntimeException("Offset '$offset' does not exist !"); | |
} | |
return $this->data[$offset]; | |
} | |
public function offsetSet($offset, $value) | |
{ | |
$this->data[$offset] = $value; | |
} | |
public function offsetUnset($offset) | |
{ | |
unset($this->data[$offset]); | |
} | |
} | |
echo $twig->render( | |
"{{ view.vars }}", | |
array('view' => new TwigTest()) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment