-
-
Save xthiago/ad5bce2f7d39bdd54b6f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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); | |
} | |
} |
This file contains hidden or 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
{% 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