/**
* Initializes arrays of filters and functions.
*/
private function lazyInit()
{
$stringyClass = new \ReflectionClass('Stringy\\Stringy');
$methods = $stringyClass->getMethods(\ReflectionMethod::IS_PUBLIC);
$names = array_map(function ($value) {
return $value->getName();
}, $methods);
foreach ($names as $name) {
if (in_array($name, self::EXCLUDE_FUNCTIONS)) {
continue;
}
$method = $stringyClass->getMethod($name);
// Get the return type from the doc comment
$doc = $method->getDocComment();
if (strpos($doc, '@return bool')) {
// Don't add functions which have the same name as any already in the environment
if ($this->environment->getFunction($name)) {
continue;
}
$this->functions[$name] = new \Twig_SimpleFunction($name, function () use($name) {
return call_user_func_array(['Stringy\\StaticStringy', $name], func_get_args());
});
} else {
// Don't add filters which have the same name as any already in the environment
if ($this->environment->getFilter($name)) {
continue;
}
$this->filters[$name] = new \Twig_SimpleFilter($name, function () use($name) {
return call_user_func_array(['Stringy\\StaticStringy', $name], func_get_args());
});
}
}
}