{
return array(
new Twig_SimpleFunction('range', 'range'),
- new Twig_SimpleFunction('constant', 'constant'),
+ new Twig_SimpleFunction('constant', 'twig_constant'),
new Twig_SimpleFunction('cycle', 'twig_cycle'),
new Twig_SimpleFunction('random', 'twig_random', array('needs_environment' => true)),
new Twig_SimpleFunction('date', 'twig_date_converter', array('needs_environment' => true)),
$sandbox->disableSandbox();
}
}
+
+/**
+ * Wrapper around constant() provides the ability to get constants
+ * from instances as well as class/global constants.
+ *
+ * @param string $constant The name of the constant.
+ * @param null|mixed $object The object to get the constant from.
+ *
+ * @return mixed
+ */
+function twig_constant($constant, $object = null)
+{
+ if (!$object) {
+ return constant($constant);
+ }
+ $class = get_class($object);
+
+ return constant($class.'::'.$constant);
+}