當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。