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


PHP Twig_Environment::getExtension方法代码示例

本文整理汇总了PHP中Twig_Environment::getExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::getExtension方法的具体用法?PHP Twig_Environment::getExtension怎么用?PHP Twig_Environment::getExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Twig_Environment的用法示例。


在下文中一共展示了Twig_Environment::getExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * @param EmailTemplate                  $value
  * @param Constraint|EmailTemplateSyntax $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     // prepare templates to be validated
     $itemsToValidate = [['field' => 'subject', 'locale' => null, 'template' => $value->getSubject()], ['field' => 'content', 'locale' => null, 'template' => $value->getContent()]];
     $translations = $value->getTranslations();
     foreach ($translations as $trans) {
         if (in_array($trans->getField(), ['subject', 'content'])) {
             $itemsToValidate[] = ['field' => $trans->getField(), 'locale' => $trans->getLocale(), 'template' => $trans->getContent()];
         }
     }
     /** @var \Twig_Extension_Sandbox $sandbox */
     $sandbox = $this->twig->getExtension('sandbox');
     $sandbox->enableSandbox();
     // validate templates' syntax
     $errors = [];
     foreach ($itemsToValidate as &$item) {
         try {
             $this->twig->parse($this->twig->tokenize($item['template']));
         } catch (\Twig_Error_Syntax $e) {
             $errors[] = ['field' => $item['field'], 'locale' => $item['locale'], 'error' => $e->getMessage()];
         }
     }
     $sandbox->disableSandbox();
     // add violations for found errors
     if (!empty($errors)) {
         foreach ($errors as $error) {
             $this->context->addViolation($constraint->message, ['{{ field }}' => $this->getFieldLabel(ClassUtils::getClass($value), $error['field']), '{{ locale }}' => $this->getLocaleName($error['locale']), '{{ error }}' => $error['error']]);
         }
     }
 }
开发者ID:xamin123,项目名称:platform,代码行数:34,代码来源:EmailTemplateSyntaxValidator.php

示例2: configure

 public function configure(\Twig_Environment $environment)
 {
     $environment->getExtension('core')->setDateFormat($this->dateFormat, $this->intervalFormat);
     if (null !== $this->timezone) {
         $environment->getExtension('core')->setTimezone($this->timezone);
     }
     $environment->getExtension('core')->setNumberFormat($this->decimals, $this->decimalPoint, $this->thousandsSeparator);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:8,代码来源:EnvironmentConfigurator.php

示例3: extractTemplate

 protected function extractTemplate($template, MessageCatalogue $catalogue)
 {
     $visitor = $this->twig->getExtension('Symfony\\Bridge\\Twig\\Extension\\TranslationExtension')->getTranslationNodeVisitor();
     $visitor->enable();
     $this->twig->parse($this->twig->tokenize(new \Twig_Source($template, '')));
     foreach ($visitor->getMessages() as $message) {
         $catalogue->set(trim($message[0]), $this->prefix . trim($message[0]), $message[1] ?: $this->defaultDomain);
     }
     $visitor->disable();
 }
开发者ID:yceruto,项目名称:symfony,代码行数:10,代码来源:TwigExtractor.php

示例4: extractTemplate

 protected function extractTemplate($template, MessageCatalogue $catalogue)
 {
     $visitor = $this->twig->getExtension('translator')->getTranslationNodeVisitor();
     $visitor->enable();
     $this->twig->parse($this->twig->tokenize($template));
     foreach ($visitor->getMessages() as $message) {
         $catalogue->set(trim($message[0]), $this->prefix . trim($message[0]), $message[1] ? $message[1] : $this->defaultDomain);
     }
     $visitor->disable();
 }
开发者ID:tejdeeps,项目名称:tejcs.com,代码行数:10,代码来源:TwigExtractor.php

示例5: onKernelRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if ($event->getRequestType() != HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     $securityContext = $this->securityContext;
     if ($securityContext && $securityContext->getToken() instanceof TokenInterface && $securityContext->getToken()->getUser() instanceof TimeZoneInterface) {
         $timeZone = $securityContext->getToken()->getUser()->getTimezone();
         if ($timeZone) {
             $this->twigEnvironment->getExtension('core')->setTimezone($timeZone);
         }
     }
 }
开发者ID:geoffreytran,项目名称:zym,代码行数:16,代码来源:TwigDateListener.php

示例6: 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

示例7: 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

示例8: getTwig

 /**
  * Get Twig-instance
  *
  * @return Twig_Environment
  */
 protected static function getTwig()
 {
     if (!static::$twig) {
         $loader = new \Twig_Loader_Filesystem(PATH_APP . '/views');
         static::$twig = new \Twig_Environment($loader, array('cache' => MAIN_SERVER ? PATH_DATA . '/twig-cache' : null, 'strict_variables' => true, 'autoescape' => false));
         static::$twig->getExtension('core')->setNumberFormat(2, ',', ' ');
         static::$twig->addExtension(new \Kofradia\Twig\Date());
         static::$twig->addExtension(new \Kofradia\Twig\Counter());
         static::$twig->addExtension(new \Kofradia\Twig\Render());
         static::$twig->addExtension(new \Kofradia\Twig\Helpers());
         static::$twig->addGlobal("page", \ess::$b->page);
         static::$twig->addGlobal("helper", new \Kofradia\Twig\TemplateHelper());
     }
     return static::$twig;
 }
开发者ID:Kuzat,项目名称:kofradia,代码行数:20,代码来源:View.php

示例9: 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

示例10: checkNode

    /**
     * Extracts formulae from filter function nodes.
     *
     * @return array|null The formula
     */
    private function checkNode(\Twig_NodeInterface $node, \Twig_Environment $env)
    {
        if ($node instanceof \Twig_Node_Expression_Function) {
            $name = $node->getNode('name')->getAttribute('name');
            if ($env->getFunction($name) instanceof AsseticFilterFunction) {
                $arguments = array();
                foreach ($node->getNode('arguments') as $argument) {
                    $arguments[] = eval('return '.$env->compile($argument).';');
                }

                $invoker = $env->getExtension('assetic')->getFilterInvoker($name);
                $factory = $invoker->getFactory();

                $inputs = isset($arguments[0]) ? (array) $arguments[0] : array();
                $filters = $invoker->getFilters();
                $options = array_replace($invoker->getOptions(), isset($arguments[1]) ? $arguments[1] : array());

                if (!isset($options['name'])) {
                    $options['name'] = $factory->generateAssetName($inputs, $filters);
                }

                return array($inputs, $filters, $options);
            }
        }
    }
开发者ID:nacef,项目名称:symfony,代码行数:30,代码来源:AsseticNodeVisitor.php

示例11: __construct

 public function __construct(\Twig_Environment $twig, LoggerInterface $logger = null)
 {
     $this->twig = $twig;
     $this->logger = $logger;
     $globals = $twig->getExtension('assetic')->getGlobals();
     $this->debug = $globals['assetic']['debug'];
 }
开发者ID:wake,项目名称:twig-assetic-fixer,代码行数:7,代码来源:TwigFormulaLoader.php

示例12: renderFragment

 /**
  * Renders fragment by window state.
  *
  * @param \Twig_Environment $environment
  * @param AbstractWindowsState $windowState
  *
  * @return string
  */
 public function renderFragment(\Twig_Environment $environment, AbstractWindowsState $windowState)
 {
     $result = '';
     $scheduleDelete = false;
     $windowState->setRenderedSuccessfully(false);
     try {
         $uri = $this->windowsStateRequestManager->getUri($windowState->getData());
         /** @var HttpKernelExtension $httpKernelExtension */
         $httpKernelExtension = $environment->getExtension('http_kernel');
         $result = $httpKernelExtension->renderFragment($uri);
         $windowState->setRenderedSuccessfully(true);
         return $result;
     } catch (NotFoundHttpException $e) {
         $scheduleDelete = true;
     } catch (\InvalidArgumentException $e) {
         $scheduleDelete = true;
     }
     if ($scheduleDelete) {
         try {
             $this->windowsStateManagerRegistry->getManager()->deleteWindowsState($windowState->getId());
         } catch (AccessDeniedException $e) {
             return $result;
         }
     }
     return $result;
 }
开发者ID:ramunasd,项目名称:platform,代码行数:34,代码来源:WindowsExtension.php

示例13: 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

示例14: testCustomEscaper

 public function testCustomEscaper()
 {
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->getExtension('core')->setEscaper('foo', 'foo_escaper_for_test');
     $this->assertEquals('fooUTF-8', twig_escape_filter($twig, 'foo', 'foo'));
     $this->assertEquals('UTF-8', twig_escape_filter($twig, null, 'foo'));
     $this->assertEquals('42UTF-8', twig_escape_filter($twig, 42, 'foo'));
 }
开发者ID:Dren-x,项目名称:mobitnew,代码行数:8,代码来源:CoreTest.php

示例15: extractTemplate

 /**
  * Extract messages from a single template
  *
  * @param                                                 $templatePath
  * @param \Symfony\Component\Translation\MessageCatalogue $catalogue
  * @return string
  */
 public function extractTemplate($templatePath, MessageCatalogue $catalogue)
 {
     $content = file_get_contents($templatePath);
     $translator = $this->twig->getExtension('translator');
     /**
      * @var TranslationNodeVisitor $visitor
      */
     $visitor = $translator->getTranslationNodeVisitor();
     $visitor->enable();
     $tokens = $this->twig->tokenize($content);
     $this->twig->parse($tokens);
     foreach ($visitor->getMessages() as $message) {
         $catalogue->set(trim($message[0]), $this->prefix . trim($message[0]), $message[1] ? $message[1] : $this->defaultDomain);
     }
     $visitor->disable();
     return $content;
 }
开发者ID:opensoft,项目名称:translocation-bundle,代码行数:24,代码来源:TwigExtractor.php


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