当前位置: 首页>>代码示例>>PHP>>正文


PHP Twig_Environment::hasExtension方法代码示例

本文整理汇总了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)));
 }
开发者ID:sitesupra,项目名称:sitesupra,代码行数:10,代码来源:TwigProcessor.php

示例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;
     }
 }
开发者ID:azzra,项目名称:aceeditor-bundle,代码行数:17,代码来源:AceEditorExtension.php

示例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;
     }
 }
开发者ID:electromuis,项目名称:aceeditor-bundle,代码行数:14,代码来源:AceEditorExtension.php

示例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;
 }
开发者ID:matthecat,项目名称:twig-whitespace-collapse-extension,代码行数:26,代码来源:WhitespaceCollapser.php

示例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;
     }
 }
开发者ID:nmcteam,项目名称:Twig,代码行数:8,代码来源:Escaper.php

示例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);
 }
开发者ID:hostnet,项目名称:form-twig-bridge,代码行数:8,代码来源:PhpRenderer.php

示例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);
 }
开发者ID:byteincoffee,项目名称:doctrine-extensions-bundle,代码行数:8,代码来源:AssetsSpec.php

示例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;
 }
开发者ID:bobseven,项目名称:Slim-Blog,代码行数:22,代码来源:Optimizer.php

示例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;
 }
开发者ID:Zyko0,项目名称:Baikal,代码行数:21,代码来源:Escaper.php

示例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;
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:19,代码来源:Escaper.php

示例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();
    }
}
开发者ID:stler,项目名称:NMFrame,代码行数:37,代码来源:Core.php

示例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'));
 }
开发者ID:bigbitecreative,项目名称:wordpress-git-content,代码行数:9,代码来源:EnvironmentTest.php

示例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);
     }
 }
开发者ID:weierophinney,项目名称:zend-expressive-twigrenderer,代码行数:24,代码来源:TwigRendererFactory.php

示例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);
         }
     }
 }
开发者ID:RaphaelYan,项目名称:TwigGenerator,代码行数:13,代码来源:BaseBuilder.php


注:本文中的Twig_Environment::hasExtension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。