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


PHP Twig_Environment::setLoader方法代码示例

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


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

示例1: render

 /**
  * Render a string
  *
  * A special option in the $locals array can be used to define the Twital adapter to use.
  * The array key is `__twital-adapter`, and the value is an instance of `\Goetas\Twital\SourceAdapter`
  *
  * @param string $template The template content to render
  * @param array $locals The variable to use in template
  * @return null|string
  *
  * @throws \Twig_Error_Loader
  * @throws \Twig_Error_Runtime
  * @throws \Twig_Error_Syntax
  */
 public function render($template, array $locals = array())
 {
     if (array_key_exists('__twital-adapter', $locals)) {
         $this->stringLoader->addSourceAdapter('/.*/', $locals['__twital-adapter']);
     }
     // Render the file using the straight string.
     $this->environment->setLoader($this->stringLoader);
     return $this->environment->render($template, $locals);
 }
开发者ID:MacFJA,项目名称:phptransformer-twital,代码行数:23,代码来源:TwitalTransformer.php

示例2: addDir

 /**
  * add a directory to template search dirs
  * @param string $directory
  * @param bool|true $primary
  * @return ITemplateEngine|void
  */
 public function addDir($directory, $primary = true)
 {
     if ($primary) {
         $this->twigLoader->prependPath($directory);
     } else {
         $this->twigLoader->addPath($directory);
     }
     $this->twigEnv->setLoader($this->twigLoader);
     return $this;
 }
开发者ID:aelix,项目名称:framework,代码行数:16,代码来源:TwigTemplateEngine.php

示例3: setUp

 protected function setUp()
 {
     if (!class_exists('Twig_Environment')) {
         $this->markTestSkipped('Twig is not installed.');
     }
     $this->mediaStorage = new FilesystemMediaStorage(__DIR__ . "/fixtures/stored", "/project/web/media/", "http://localhost/project/web/media/", FALSE);
     $this->twig = new \Twig_Environment();
     $this->twig->setLoader(new \Twig_Loader_Filesystem(__DIR__ . '/fixtures/templates'));
     $this->twig->addExtension(new TwigMediaStorageExtension($this->mediaStorage, TRUE));
 }
开发者ID:Kilix,项目名称:OryzoneMediaStorageBundle,代码行数:10,代码来源:TwigMediaStorageExtensionTest.php

示例4: setUp

 protected function setUp()
 {
     if (!class_exists('Twig_Environment')) {
         $this->markTestSkipped('Twig is not installed.');
     }
     $this->mapper = $this->getMock('Midgard\\CreatePHP\\RdfMapperInterface');
     $xmlDriver = new RdfDriverXml(array(__DIR__ . '/../../Metadata/rdf-twig'));
     $this->factory = new RdfTypeFactory($this->mapper, $xmlDriver);
     $this->twig = new \Twig_Environment();
     $this->twig->setLoader(new \Twig_Loader_Filesystem(__DIR__ . '/templates'));
     $this->twig->addExtension(new CreatephpExtension($this->factory));
 }
开发者ID:waifei,项目名称:createphp,代码行数:12,代码来源:CreatephpExtensionTest.php

示例5: _run

 /**
  * 表示するためのファイルを組み立て
  *
  * @access protected
  */
 protected function _run()
 {
     // 引数のファイルパスをview scriptまでのパスとcontroller/action.:suffixの形式に分断する
     $paths = $this->_parseFilePath(func_get_arg(0));
     // view scriptまでのパスを指定
     $this->_twig->setLoader(new Twig_Loader_Filesystem($paths["path"]));
     // 登録した配列の0番目のViewScriptをテンプレートとして読み込み
     $template = $this->_twig->loadTemplate($paths["file"]);
     // APPLICATION_ENVをTwigから利用出来るようにするため変数に入れておく
     $this->env = APPLICATION_ENV;
     echo $template->render($this->getVars());
 }
开发者ID:Nully,项目名称:zf_twig,代码行数:17,代码来源:Twig.php

示例6: render

 /**
  * @param  \Twig_Environment $env
  * @param                    $context
  * @param  FormView          $form
  * @param  string            $formVariableName
  * @return array
  */
 public function render(\Twig_Environment $env, $context, FormView $form, $formVariableName = 'form')
 {
     $this->formVariableName = $formVariableName;
     $this->formConfig = new FormConfig();
     $this->context = $context;
     $this->env = $env;
     $tmpLoader = $env->getLoader();
     $env->setLoader(new \Twig_Loader_Chain([$tmpLoader, new \Twig_Loader_String()]));
     $this->renderBlock($form);
     $env->setLoader($tmpLoader);
     return $this->formConfig->toArray();
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:19,代码来源:DataBlocks.php

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

示例8: render

 /**
  * @param \Twig_Environment $env
  * @param array             $context
  * @param FormView          $form
  * @param string            $formVariableName
  *
  * @return array
  */
 public function render(\Twig_Environment $env, $context, FormView $form, $formVariableName = 'form')
 {
     // remember current loader
     $originalLoader = $env->getLoader();
     // replace the loader
     $env->setLoader(new \Twig_Loader_Chain(array($originalLoader, new \Twig_Loader_String())));
     // build blocks
     $builder = new DataBlockBuilder(new TwigTemplateRenderer($env, $context), $formVariableName);
     $result = $builder->build($form);
     // restore the original loader
     $env->setLoader($originalLoader);
     return $result->toArray();
 }
开发者ID:Maksold,项目名称:platform,代码行数:21,代码来源:DataBlockRenderer.php

示例9: twig_template_from_string

/**
 * Loads a template from a string.
 *
 * <pre>
 * {{ include(template_from_string("Hello {{ name }}")) }}
 * </pre>
 *
 * @param Twig_Environment $env      A Twig_Environment instance
 * @param string           $template A template as a string
 *
 * @return Twig_Template A Twig_Template instance
 */
function twig_template_from_string(Twig_Environment $env, $template)
{
    $name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false));
    $loader = new Twig_Loader_Chain(array(new Twig_Loader_Array(array($name => $template)), $current = $env->getLoader()));
    $env->setLoader($loader);
    try {
        $template = $env->loadTemplate($name);
    } catch (Exception $e) {
        $env->setLoader($current);
        throw $e;
    }
    $env->setLoader($current);
    return $template;
}
开发者ID:jesusmarket,项目名称:jesusmarket,代码行数:26,代码来源:StringLoader.php

示例10: setUp

 protected function setUp()
 {
     if (!class_exists('Twig_Environment')) {
         $this->markTestSkipped('Twig is not installed.');
     }
     $this->am = $this->getMock('Assetic\\AssetManager');
     $this->fm = $this->getMock('Assetic\\FilterManager');
     $this->valueSupplier = $this->getMock('Assetic\\ValueSupplierInterface');
     $this->factory = new AssetFactory(__DIR__ . '/templates');
     $this->factory->setAssetManager($this->am);
     $this->factory->setFilterManager($this->fm);
     $this->twig = new \Twig_Environment();
     $this->twig->setLoader(new \Twig_Loader_Filesystem(__DIR__ . '/templates'));
     $this->twig->addExtension(new AsseticExtension($this->factory, array(), $this->valueSupplier));
 }
开发者ID:kebenxiaoming,项目名称:owncloudRedis,代码行数:15,代码来源:AsseticExtensionTest.php

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

示例12: getEnv

 private function getEnv()
 {
     $env = new \Twig_Environment();
     $env->addTokenParser(new TwigJsTokenParser());
     $env->setLoader(new \Twig_Loader_String());
     return $env;
 }
开发者ID:raphydev,项目名称:onep,代码行数:7,代码来源:TwigJsTokenParserTest.php

示例13: twig_template_from_string

/**
 * Loads a template from a string.
 *
 * <pre>
 * {% include template_from_string("Hello {{ name }}") }}
 * </pre>
 *
 * @param Twig_Environment $env      A Twig_Environment instance
 * @param string           $template A template as a string
 *
 * @return Twig_Template A Twig_Template instance
 */
function twig_template_from_string(Twig_Environment $env, $template)
{
    static $loader;
    if (null === $loader) {
        $loader = new Twig_Loader_String();
    }
    $current = $env->getLoader();
    $env->setLoader($loader);
    try {
        $template = $env->loadTemplate($template);
    } catch (Exception $e) {
        $env->setLoader($current);
        throw $e;
    }
    $env->setLoader($current);
    return $template;
}
开发者ID:ideafresh,项目名称:Slim-Boilerplate,代码行数:29,代码来源:StringLoader.php

示例14: renderString

 /**
  * @param string $string
  * @return string
  */
 public function renderString($string)
 {
     // no rendering if empty
     if (empty($string)) {
         return $string;
     }
     // see Twig\Extensions\Twig_Extension_StringLoader
     $name = '__twig_string__';
     // get current loader
     $loader = $this->environment->getLoader();
     // set loader chain with new array loader
     $this->environment->setLoader(new Twig_Loader_Chain(array(new Twig_Loader_Array(array($name => $string)), $loader)));
     // render string
     $rendered = $this->environment->render($name);
     // reset current loader
     $this->environment->setLoader($loader);
     return $rendered;
 }
开发者ID:schpill,项目名称:standalone,代码行数:22,代码来源:twig.php

示例15: parseString

 /**
  * Sets the parser for the environment to Twig_Loader_String, and parsed the string $string.
  * 
  * @param \Twig_Environment $environment
  * @param array $context
  * @param string $string
  * @return string 
  */
 protected function parseString(\Twig_Environment $environment, $context, $string)
 {
     try {
         $environment->setLoader(new \Twig_Loader_String());
         return $environment->render($string, $context);
     } catch (\Exception $exc) {
         return null;
     }
 }
开发者ID:sgranada,项目名称:kijho-mailer,代码行数:17,代码来源:EvaluateExtension.php


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