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


PHP Twig_Environment::getLoader方法代码示例

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


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

示例1: parse

 /**
  * @param string $template
  * @return array
  * @throws \Werkint\Bundle\TemplatingBundle\Exception\TemplateNotFoundException
  */
 public function parse($template)
 {
     $modules = [$template];
     $worked = [];
     while ($name = array_shift($modules)) {
         if (isset($worked[$name])) {
             continue;
         }
         try {
             $source = $this->templating->getLoader()->getSource($name);
         } catch (\Twig_Error_Loader $exception) {
             throw new TemplateNotFoundException($template);
         }
         // Инклуды
         preg_match_all('!%\\s*(include|extends)\\s*(.+?)\\s+!', $source, $m);
         $m = array_map(function ($name) {
             return substr($name, 1, strlen($name) - 2);
         }, array_filter($m[2], function ($name) {
             return preg_match('!^[\'"].+?[\'"]$!', $name);
         }));
         $modules = array_merge($modules, $m);
         $worked[$name] = $source;
     }
     return $worked;
 }
开发者ID:werkint,项目名称:templating-bundle,代码行数:30,代码来源:TemplateParser.php

示例2: parse

 public function parse($buffer, $context = array())
 {
     /** @var \Twig_Loader_Array $loader */
     $loader = $this->twigEnvironment->getLoader();
     $loader->setTemplate('__TEMPLATE__', $buffer);
     return $this->twigEnvironment->render('__TEMPLATE__', $context);
 }
开发者ID:Ainschy,项目名称:contao-message,代码行数:7,代码来源:TagReplacementService.php

示例3: getTemplateName

 /**
  * Get the template name.
  *
  * @return string
  */
 public function getTemplateName()
 {
     $template = $this->configuration['template'];
     if (!$this->environment->getLoader()->exists($template)) {
         $this->environment->getLoader()->addPath(__DIR__ . '/../Resources/views');
     }
     return $template;
 }
开发者ID:neimheadh,项目名称:bootstrap-bundle,代码行数:13,代码来源:NavbarExtension.php

示例4: getPlaces

 /**
  * {@inheritDoc}
  */
 public function getPlaces($layoutSrc)
 {
     $tokenStream = $this->twig->tokenize($this->twig->getLoader()->getSource($layoutSrc));
     $collector = new PlaceHolderNodeCollector();
     $traverser = new \Twig_NodeTraverser($this->twig, array($collector));
     $traverser->traverse($this->twig->parse($tokenStream));
     return $collector->getCollectedNames();
 }
开发者ID:sitesupra,项目名称:sitesupra,代码行数:11,代码来源:TwigProcessor.php

示例5: getTemplateName

 /**
  * Get the template name.
  *
  * @return string
  */
 public function getTemplateName()
 {
     $template = 'bs_breadcrumb/breadcrumb.html.twig';
     if (!$this->environment->getLoader()->exists($template)) {
         $this->environment->getLoader()->addPath(__DIR__ . '/../Resources/views');
     }
     return $template;
 }
开发者ID:neimheadh,项目名称:bootstrap-bundle,代码行数:13,代码来源:BreadcrumbExtension.php

示例6: file

 public function file($path, $data = array(), $mergeData = array())
 {
     if (!file_exists($path)) {
         return false;
     }
     $filePath = dirname($path);
     $fileName = basename($path);
     $this->twig->getLoader()->addPath($filePath);
     return new TwigView($this, $fileName, $data);
 }
开发者ID:egiw,项目名称:lumen-twig,代码行数:10,代码来源:TwigFactory.php

示例7: testFormatter

 public function testFormatter()
 {
     $loader = new MyStringLoader();
     $twig = new \Twig_Environment($loader);
     $formatter = new TwigFormatter($twig);
     // Checking, that formatter can process twig template, passed as string
     $this->assertEquals('0,1,2,3,', $formatter->transform('{% for i in range(0, 3) %}{{ i }},{% endfor %}'));
     // Checking, that formatter does not changed loader
     $this->assertNotInstanceOf('\\Twig_Loader_String', $twig->getLoader());
     $this->assertInstanceOf('Sonata\\FormatterBundle\\Tests\\Formatter\\MyStringLoader', $twig->getLoader());
 }
开发者ID:OskarStark,项目名称:SonataFormatterBundle,代码行数:11,代码来源:TwigFormatterTest.php

示例8: transform

 /**
  * {@inheritdoc}
  */
 public function transform($text)
 {
     // Here we temporary changing twig environment loader to Chain loader with Twig_Loader_Array as first loader, which contains only one our template reference
     $oldLoader = $this->twig->getLoader();
     $hash = sha1($text);
     $chainLoader = new \Twig_Loader_Chain();
     $chainLoader->addLoader(new \Twig_Loader_Array(array($hash => $text)));
     $chainLoader->addLoader($oldLoader);
     $this->twig->setLoader($chainLoader);
     $result = $this->twig->render($hash);
     $this->twig->setLoader($oldLoader);
     return $result;
 }
开发者ID:devcodixis,项目名称:SonataFormatterBundle,代码行数:16,代码来源:TwigFormatter.php

示例9: boot

 public function boot()
 {
     $configPath = __DIR__ . '/../config/form.php';
     $this->publishes([$configPath => config_path('form.php')], 'config');
     if ($this->app->bound(\Twig_Environment::class)) {
         /** @var \Twig_Environment $twig */
         $twig = $this->app->make(\Twig_Environment::class);
     } else {
         $twig = new \Twig_Environment(new \Twig_Loader_Chain([]));
     }
     $loader = $twig->getLoader();
     // If the loader is not already a chain, make it one
     if (!$loader instanceof \Twig_Loader_Chain) {
         $loader = new \Twig_Loader_Chain([$loader]);
         $twig->setLoader($loader);
     }
     $reflected = new \ReflectionClass(FormExtension::class);
     $path = dirname($reflected->getFileName()) . '/../Resources/views/Form';
     $loader->addLoader(new \Twig_Loader_Filesystem($path));
     /** @var TwigRenderer $renderer */
     $renderer = $this->app->make(TwigRendererInterface::class);
     $renderer->setEnvironment($twig);
     // Add the extension
     $twig->addExtension(new FormExtension($renderer));
     // trans filter is used in the forms
     $twig->addFilter(new \Twig_SimpleFilter('trans', 'trans'));
     // csrf_token needs to be replaced for Laravel
     $twig->addFunction(new \Twig_SimpleFunction('csrf_token', 'csrf_token'));
     $this->registerBladeDirectives();
 }
开发者ID:barryvdh,项目名称:laravel-form-bridge,代码行数:30,代码来源:ServiceProvider.php

示例10: __construct

    function it_should_generate_code_for_the_given_metadata(Twig $view, Filesystem $fileSystem, Loader $loader)
    {
        $view->getLoader()->willReturn($loader);
        $this->beConstructedWith($view, $fileSystem);
        $formMetadata = new FormMetadata();
        $formMetadata->populate('My\\Awesome\\LoginForm', ['username' => ['type' => 'text', 'optional' => false, 'multipleSelection' => false, 'value' => null], 'languages' => ['type' => 'select', 'optional' => true, 'multipleSelection' => true, 'value' => null], 'remember_me' => ['type' => 'checkbox', 'optional' => true, 'multipleSelection' => false, 'value' => null]]);
        $formMetadata->setTargetDirectory('src/');
        $view->render('templates/class.php.twig', ['form' => $formMetadata])->willReturn($code = <<<CODE
<?php
namespace My\\Awesome;

use EasyForms\\Elements\\Text;
use EasyForms\\Elements\\Select;
use EasyForms\\Elements\\Checkbox;
use EasyForms\\Form;

class LoginForm extends Form
{
    public function __construct()
    {
        \$this
            ->add(new Text('username'))
            ->add((new Select('languages'))->makeOptional()->enableMultipleSelection())
            ->add((new Checkbox('remember_me', 'remember'))->makeOptional())
        ;
    }
}
CODE
);
        $this->generate($formMetadata);
        $fileSystem->mkdir('src/My/Awesome')->shouldHaveBeenCalled();
        $fileSystem->dumpFile('src/My/Awesome/LoginForm.php', $code)->shouldHaveBeenCalled();
    }
开发者ID:comphppuebla,项目名称:easy-forms,代码行数:33,代码来源:FormGeneratorSpec.php

示例11: extendTwig

 /**
  * Adds extensions required for proper work with FormFactory to Twig template engine
  * @param CsrfTokenManager $csrfTokenManager
  */
 private function extendTwig($csrfTokenManager)
 {
     $translator = new Translator($this->lang);
     $translator->addLoader('xlf', new XliffFileLoader());
     $translator->addResource('xlf', $this->componentDir['form'] . '/Resources/translations/validators.en.xlf', 'en', 'validators');
     $translator->addResource('xlf', $this->componentDir['validator'] . '/Resources/translations/validators.en.xlf', 'en', 'validators');
     $formTheme = 'bootstrap_3_layout.html.twig';
     //'form_div_layout.html.twig';
     $formEngine = new TwigRendererEngine([$formTheme]);
     $twigLoader = $this->twig->getLoader();
     $newTwigLoader = new \Twig_Loader_Chain([$twigLoader, new \Twig_Loader_Filesystem([$this->componentDir['twigBridge'] . '/Resources/views/Form'])]);
     $this->twig->setLoader($newTwigLoader);
     $formEngine->setEnvironment($this->twig);
     $this->twig->addExtension(new TranslationExtension($translator));
     $this->twig->addExtension(new FormExtension(new TwigRenderer($formEngine, $csrfTokenManager)));
 }
开发者ID:pavgra,项目名称:2nova-test,代码行数:20,代码来源:AppFormFactory.php

示例12: evaluateFilter

 /**
  * Evaluate $string through the $environment and return its results
  *
  * @oaram \Twig_Environment $environment
  * @param array $context
  * @param string $string
  *
  * @return string
  */
 public function evaluateFilter(\Twig_Environment $environment, $context, $string)
 {
     $loader = $environment->getLoader();
     $parsed = $this->parseString($environment, $context, $string);
     $environment->setLoader($loader);
     return $parsed;
 }
开发者ID:symbio,项目名称:orangegate4-admin-bundle,代码行数:16,代码来源:OrangeGate4Extension.php

示例13: __construct

 /**
  * @param Twig $view
  * @param Filesystem $fileSystem
  */
 public function __construct(Twig $view, Filesystem $fileSystem)
 {
     $class = new ReflectionClass($this);
     $view->getLoader()->addPath(dirname($class->getFileName()) . '/../Resources');
     $this->view = $view;
     $this->fileSystem = $fileSystem;
 }
开发者ID:comphppuebla,项目名称:easy-forms,代码行数:11,代码来源:FormGenerator.php

示例14: initRuntime

 public function initRuntime(\Twig_Environment $environment)
 {
     $this->twigEnvironment = $environment;
     $loader = new \Twig_Loader_Filesystem();
     $loader->addPath(__DIR__ . '/../Resorces/views', 'np_navigation');
     $environment->getLoader()->addLoader($loader);
 }
开发者ID:nodepub,项目名称:navigation,代码行数:7,代码来源:NavigationTwigExtension.php

示例15: before

 /**
  * @return array[string => mixed]
  */
 public static function before()
 {
     $user = null;
     // initialize session
     Session::init();
     // setup twig
     $twig = new \Twig_Environment(new \Twig_Loader_Filesystem());
     $twig->getLoader()->addPath(__DIR__ . '/Twig');
     $twig->addGlobal('asset', Settings::load('settings')->get('asset-url'));
     $twig->addGlobal('base_url', NekoPHP::getBaseUrl());
     // add the current user object to twig, if it exists
     $user_id = Session::get('user_id');
     // set the user if a user_id is set
     if ($user_id > 0) {
         $user = new \NekoPHP\Modules\User\Models\User($user_id);
         $twig->addGlobal('cuser', $user);
     }
     // add one-time alerts
     foreach (['success', 'info', 'warning', 'error'] as $alert) {
         if (Session::existsOnce($alert)) {
             $twig->addGlobal('alert_' . $alert, Session::getOnce($alert));
         }
     }
     return ['cuser' => $user, 'twig' => $twig];
 }
开发者ID:scriptkitties,项目名称:NekoPHP,代码行数:28,代码来源:Shared.php


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