Skip to content

Instantly share code, notes, and snippets.

@xthiago
Forked from adrienbrault/extension.php
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xthiago/ad5bce2f7d39bdd54b6f to your computer and use it in GitHub Desktop.
Save xthiago/ad5bce2f7d39bdd54b6f to your computer and use it in GitHub Desktop.
<?php
class LayoutExtension extends \Twig_Extension
{
/**
* {@inheritdoc}
*/
public function getName()
{
return 'yolo';
}
/**
* {@inheritdoc}
*/
public function getTests()
{
return array(
new \Twig_SimpleTest('instanceof', array($this, 'isInstanceOf'))
);
}
public function isInstanceOf($object, $class)
{
$reflectionClass = new \ReflectionClass($class);
return $reflectionClass->isInstance($object);
}
}
{% if object is instanceof('Acme\\Foo\\Entity') %}
<p>true</p>
{% else %}
<p>false</p>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment