Created
October 18, 2013 18:02
-
-
Save adrienbrault/7045544 to your computer and use it in GitHub Desktop.
instanceof twig test
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 | |
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); | |
} | |
} |
Nice ! Thanks you for the ReflectionClass->isInstance() tips !
I just think you can remove getName() implementation because (from doc in \Twig_Extension) :
@deprecated since 1.26 (to be removed in 2.0), not used anymore internally
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
๐ ๐