protected function Twig_Environment::initExtension in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/twig/twig/lib/Twig/Environment.php \Twig_Environment::initExtension()
1 call to Twig_Environment::initExtension()
- Twig_Environment::initExtensions in vendor/
twig/ twig/ lib/ Twig/ Environment.php
File
- vendor/
twig/ twig/ lib/ Twig/ Environment.php, line 1310
Class
- Twig_Environment
- Stores the Twig configuration.
Code
protected function initExtension(Twig_ExtensionInterface $extension) {
// filters
foreach ($extension
->getFilters() as $name => $filter) {
if ($filter instanceof Twig_SimpleFilter) {
$name = $filter
->getName();
}
else {
@trigger_error(sprintf('Using an instance of "%s" for filter "%s" is deprecated. Use Twig_SimpleFilter instead.', get_class($filter), $name), E_USER_DEPRECATED);
}
$this->filters[$name] = $filter;
}
// functions
foreach ($extension
->getFunctions() as $name => $function) {
if ($function instanceof Twig_SimpleFunction) {
$name = $function
->getName();
}
else {
@trigger_error(sprintf('Using an instance of "%s" for function "%s" is deprecated. Use Twig_SimpleFunction instead.', get_class($function), $name), E_USER_DEPRECATED);
}
$this->functions[$name] = $function;
}
// tests
foreach ($extension
->getTests() as $name => $test) {
if ($test instanceof Twig_SimpleTest) {
$name = $test
->getName();
}
else {
@trigger_error(sprintf('Using an instance of "%s" for test "%s" is deprecated. Use Twig_SimpleTest instead.', get_class($test), $name), E_USER_DEPRECATED);
}
$this->tests[$name] = $test;
}
// token parsers
foreach ($extension
->getTokenParsers() as $parser) {
if ($parser instanceof Twig_TokenParserInterface) {
$this->parsers
->addTokenParser($parser);
}
elseif ($parser instanceof Twig_TokenParserBrokerInterface) {
@trigger_error('Registering a Twig_TokenParserBrokerInterface instance is deprecated.', E_USER_DEPRECATED);
$this->parsers
->addTokenParserBroker($parser);
}
else {
throw new LogicException('getTokenParsers() must return an array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances');
}
}
// node visitors
foreach ($extension
->getNodeVisitors() as $visitor) {
$this->visitors[] = $visitor;
}
// operators
if ($operators = $extension
->getOperators()) {
if (2 !== count($operators)) {
throw new InvalidArgumentException(sprintf('"%s::getOperators()" does not return a valid operators array.', get_class($extension)));
}
$this->unaryOperators = array_merge($this->unaryOperators, $operators[0]);
$this->binaryOperators = array_merge($this->binaryOperators, $operators[1]);
}
}