本文整理汇总了PHP中Twig_Environment::hasExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::hasExtension方法的具体用法?PHP Twig_Environment::hasExtension怎么用?PHP Twig_Environment::hasExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Environment
的用法示例。
在下文中一共展示了Twig_Environment::hasExtension方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* {@inheritDoc}
*/
public function process($layoutSrc, Response $response, array $placeResponses)
{
if (!$this->twig->hasExtension('supraPage')) {
throw new \UnexpectedValueException('Missing for Supra Page extension.');
}
$response->setContent($this->twig->render($layoutSrc, array('responses' => $placeResponses)));
}
示例2: includeAceEditor
/**
* Echoes the <script> tag.
*
*/
public function includeAceEditor()
{
if (!$this->environment->hasExtension('asset') || $this->editorIncluded) {
return;
}
if (!$this->editorIncluded) {
foreach (array('ace', 'ext-language_tools') as $file) {
$jsPath = $this->environment->getExtension('asset')->getAssetUrl($this->basePath . '/' . $this->mode . '/' . $file . '.js');
echo sprintf('<script src="%s" charset="utf-8" type="text/javascript"></script>', $jsPath);
}
$this->editorIncluded = true;
}
}
示例3: includeAceEditor
public function includeAceEditor()
{
if (!$this->environment->hasExtension('assets')) {
return;
}
if (!$this->editorIncluded) {
$this->editorIncluded = true;
}
if (!$this->ckeditorIncluded) {
$jsPath = $this->environment->getExtension('assets')->getAssetUrl($this->basePath . '/' . $this->mode);
echo sprintf('<script src="%s" charset="utf-8"></script>', $jsPath);
$this->ckeditorIncluded = true;
}
}
示例4: doEnterNode
protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
{
if ($node instanceof \Twig_Node_Block) {
$this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needCollapsing();
} elseif ($node instanceof WhitespaceCollapse) {
$this->statusStack[] = $node->getAttribute('value');
} elseif ($env->hasExtension('whitespace_collapser')) {
/** @var \MatTheCat\Twig\Extension\WhitespaceCollapser $extension */
$extension = $env->getExtension('whitespace_collapser');
$extensionDefault = $extension->getDefault();
if ($node instanceof \Twig_Node_Module) {
if (is_array($extensionDefault)) {
$filename = $node->getAttribute('filename');
if (substr($filename, -5) === '.twig') {
$filename = substr($filename, 0, -5);
}
$this->enabledByDefault = in_array(pathinfo($filename, PATHINFO_EXTENSION), $extensionDefault, true);
} else {
$this->enabledByDefault = $extensionDefault;
}
} elseif ($node instanceof \Twig_Node_AutoEscape) {
$this->statusStack[] = is_array($extensionDefault) ? in_array($node->getAttribute('value'), $extensionDefault) : $extensionDefault;
}
}
return $node;
}
示例5: needEscaping
protected function needEscaping(Twig_Environment $env)
{
if (count($this->statusStack)) {
return $this->statusStack[count($this->statusStack) - 1];
} else {
return $env->hasExtension('escaper') ? $env->getExtension('escaper')->isGlobal() : false;
}
}
示例6: __construct
public function __construct(\Twig_Environment $environment)
{
if (!$environment->hasExtension('form')) {
throw new \DomainException('The FormRenderer needs an environment with the FormExtension');
}
$this->environment = $environment;
$this->environment->getExtension('form')->initRuntime($this->environment);
}
示例7: let
function let(\Twig_Environment $environment, AssetsExtension $assets, FSiFilePathResolver $filePathResolver)
{
$this->beConstructedWith($filePathResolver);
$environment->hasExtension('assets')->shouldBeCalled()->willReturn(true);
$environment->getExtension('assets')->shouldBeCalled()->willReturn($assets);
$environment->getGlobals()->shouldBeCalled()->willReturn(array());
$this->initRuntime($environment);
}
示例8: optimizePrintNode
/**
* Optimizes print nodes.
*
* It replaces:
*
* * "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()"
* * "echo $this->getContext('...')" with "if (isset('...')) { echo '...' }"
*
* @param Twig_NodeInterface $node A Node
* @param Twig_Environment $env The current Twig environment
*/
protected function optimizePrintNode($node, $env)
{
if (!$node instanceof Twig_Node_Print) {
return $node;
}
if ($node->getNode('expr') instanceof Twig_Node_Expression_BlockReference || $node->getNode('expr') instanceof Twig_Node_Expression_Parent || $node->getNode('expr') instanceof Twig_Node_Expression_Name && !$env->hasExtension('sandbox') && !$env->isStrictVariables()) {
$node->getNode('expr')->setAttribute('output', true);
return $node->getNode('expr');
}
return $node;
}
示例9: enterNode
/**
* Called before child nodes are visited.
*
* @param Twig_NodeInterface $node The node to visit
* @param Twig_Environment $env The Twig environment instance
*
* @return Twig_NodeInterface The modified node
*/
public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
if ($env->hasExtension('escaper') && ($defaultStrategy = $env->getExtension('escaper')->getDefaultStrategy($node->getAttribute('filename')))) {
$this->defaultStrategy = $defaultStrategy;
}
} elseif ($node instanceof Twig_Node_AutoEscape) {
$this->statusStack[] = $node->getAttribute('value');
} elseif ($node instanceof Twig_Node_Block) {
$this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env);
}
return $node;
}
示例10: doEnterNode
/**
* {@inheritdoc}
*/
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
if ($env->hasExtension('escaper') && ($defaultStrategy = $env->getExtension('escaper')->getDefaultStrategy($node->getAttribute('filename')))) {
$this->defaultStrategy = $defaultStrategy;
}
$this->safeVars = array();
} elseif ($node instanceof Twig_Node_AutoEscape) {
$this->statusStack[] = $node->getAttribute('value');
} elseif ($node instanceof Twig_Node_Block) {
$this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env);
} elseif ($node instanceof Twig_Node_Import) {
$this->safeVars[] = $node->getNode('var')->getAttribute('name');
}
return $node;
}
示例11: twig_include
/**
* Renders a template.
*
* @param Twig_Environment $env
* @param array $context
* @param string|array $template The template to render or an array of templates to try consecutively
* @param array $variables The variables to pass to the template
* @param bool $withContext
* @param bool $ignoreMissing Whether to ignore missing templates or not
* @param bool $sandboxed Whether to sandbox the template or not
*
* @return string The rendered template
*/
function twig_include(Twig_Environment $env, $context, $template, $variables = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false)
{
$alreadySandboxed = false;
$sandbox = null;
if ($withContext) {
$variables = array_merge($context, $variables);
}
if ($isSandboxed = $sandboxed && $env->hasExtension('sandbox')) {
$sandbox = $env->getExtension('sandbox');
if (!($alreadySandboxed = $sandbox->isSandboxed())) {
$sandbox->enableSandbox();
}
}
try {
return $env->resolveTemplate($template)->render($variables);
} catch (Twig_Error_Loader $e) {
if (!$ignoreMissing) {
throw $e;
}
}
if ($isSandboxed && !$alreadySandboxed) {
$sandbox->disableSandbox();
}
}
示例12: testHasGetExtensionByClassName
public function testHasGetExtensionByClassName()
{
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
$twig->addExtension($ext = new Twig_Tests_EnvironmentTest_Extension());
$this->assertTrue($twig->hasExtension('Twig_Tests_EnvironmentTest_Extension'));
$this->assertTrue($twig->hasExtension('\\Twig_Tests_EnvironmentTest_Extension'));
$this->assertSame($ext, $twig->getExtension('Twig_Tests_EnvironmentTest_Extension'));
$this->assertSame($ext, $twig->getExtension('\\Twig_Tests_EnvironmentTest_Extension'));
}
示例13: injectExtensions
/**
* Inject extensions into the TwigEnvironment instance.
*
* @param TwigEnvironment $environment
* @param ContainerInterface $container
* @param array $extensions
* @throws Exception\InvalidExtensionException
*/
private function injectExtensions(TwigEnvironment $environment, ContainerInterface $container, array $extensions)
{
foreach ($extensions as $extension) {
// Load the extension from the container
if (is_string($extension) && $container->has($extension)) {
$extension = $container->get($extension);
}
if (!$extension instanceof Twig_ExtensionInterface) {
throw new Exception\InvalidExtensionException(sprintf('Twig extension must be an instance of Twig_ExtensionInterface; "%s" given,', is_object($extension) ? get_class($extension) : gettype($extension)));
}
if ($environment->hasExtension($extension->getName())) {
continue;
}
$environment->addExtension($extension);
}
}
示例14: loadTwigExtensions
protected function loadTwigExtensions(\Twig_Environment $twig)
{
foreach ($this->twigExtensions as $twigExtensionName) {
if (is_object($twigExtensionName)) {
$twigExtension = $twigExtensionName;
} else {
$twigExtension = new $twigExtensionName();
}
if (!$twig->hasExtension($twigExtension->getName())) {
$twig->addExtension($twigExtension);
}
}
}