/** * Gets a TokenParser suitable for a tag. * * @param string $tag A tag name * * @return null|Twig_TokenParserInterface A Twig_TokenParserInterface or null if no suitable TokenParser was found */ public function getTokenParser($tag) { if ($this->environment->getFunction($tag)) { return $this->viewHelperParser; } return null; }
/** * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator * @return \ZfcTwig\Twig\Environment * @throws InvalidArgumentException */ public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Configuration'); $config = $config['zfctwig']; $loader = $serviceLocator->get('TwigViewResolver'); $twig = new Environment($loader, $config['config']); $twig->addExtension(new Extension($twig, $serviceLocator)); $manager = $serviceLocator->get('TwigViewHelperManager'); $twig->setManager($manager); foreach ($config['extensions'] as $ext) { if (!is_string($ext)) { throw new InvalidArgumentException('Extension name must be a string'); } $twig->addExtension(new $ext()); } return $twig; }