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


PHP Twig_Environment::addRuntimeLoader方法代码示例

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


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

示例1: renderTemplate

 protected function renderTemplate(FragmentHandler $renderer, $template = '{{ render("foo") }}')
 {
     $loader = new \Twig_Loader_Array(array('index' => $template));
     $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
     $twig->addExtension(new HttpKernelExtension());
     $loader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock();
     $loader->expects($this->any())->method('load')->will($this->returnValueMap(array(array('Symfony\\Bridge\\Twig\\Extension\\HttpKernelRuntime', new HttpKernelRuntime($renderer)))));
     $twig->addRuntimeLoader($loader);
     return $twig->render('index');
 }
开发者ID:symfony,项目名称:symfony,代码行数:10,代码来源:HttpKernelExtensionTest.php

示例2: setUp

 protected function setUp()
 {
     parent::setUp();
     $loader = new \Twig_Loader_Filesystem([__DIR__ . '/../../Resources/theme', __DIR__ . '/../Resources/views']);
     $environment = new \Twig_Environment($loader, ['debug' => true, 'strict_variables' => true]);
     $environment->addGlobal('global_var', 'global_value');
     $environment->addExtension(new DatagridExtension());
     $rendererEngine = new TwigRendererEngine($environment, ['datagrid.html.twig']);
     $this->renderer = new TwigRenderer($rendererEngine);
     $loader = $this->prophesize(\Twig_RuntimeLoaderInterface::class);
     $loader->load(TwigRenderer::class)->willReturn($this->renderer);
     $environment->addRuntimeLoader($loader->reveal());
     $this->twig = $environment;
 }
开发者ID:rollerworks,项目名称:datagrid-twig,代码行数:14,代码来源:DatagridExtensionTest.php

示例3: setUp

 protected function setUp()
 {
     parent::setUp();
     $loader = new \Twig_Loader_Filesystem([__DIR__ . '/../../Resources/theme']);
     $cacheDir = __DIR__ . '/twig-perf';
     if (!file_exists($cacheDir)) {
         @mkdir($cacheDir);
     }
     $environment = new \Twig_Environment($loader, ['debug' => true, 'strict_variables' => true, 'cache' => $cacheDir]);
     $environment->addExtension(new DatagridExtension());
     $rendererEngine = new TwigRendererEngine($environment, ['datagrid.html.twig']);
     $this->renderer = new TwigRenderer($rendererEngine);
     $loader = $this->prophesize(\Twig_RuntimeLoaderInterface::class);
     $loader->load(TwigRenderer::class)->willReturn($this->renderer);
     $environment->addRuntimeLoader($loader->reveal());
     // load the theme template to ensure a compile, we are only interested in the rendering speed
     $environment->loadTemplate('datagrid.html.twig');
 }
开发者ID:rollerworks,项目名称:datagrid-twig,代码行数:18,代码来源:DatagridExtensionPerformanceTest.php

示例4: registerTwigRuntimeLoader

 protected function registerTwigRuntimeLoader(\Twig_Environment $environment, TwigRenderer $renderer)
 {
     $loader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock();
     $loader->expects($this->any())->method('load')->will($this->returnValueMap(array(array('Symfony\\Bridge\\Twig\\Form\\TwigRenderer', $renderer))));
     $environment->addRuntimeLoader($loader);
 }
开发者ID:symfony,项目名称:symfony,代码行数:6,代码来源:RuntimeLoaderProvider.php

示例5: testAddRuntimeLoader

 public function testAddRuntimeLoader()
 {
     $runtimeLoader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock();
     $runtimeLoader->expects($this->any())->method('load')->will($this->returnValue(new Twig_Tests_EnvironmentTest_Runtime()));
     $loader = new Twig_Loader_Array(array('func_array' => '{{ from_runtime_array("foo") }}', 'func_array_default' => '{{ from_runtime_array() }}', 'func_array_named_args' => '{{ from_runtime_array(name="foo") }}', 'func_string' => '{{ from_runtime_string("foo") }}', 'func_string_default' => '{{ from_runtime_string() }}', 'func_string_named_args' => '{{ from_runtime_string(name="foo") }}'));
     $twig = new Twig_Environment($loader);
     $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime());
     $twig->addRuntimeLoader($runtimeLoader);
     $this->assertEquals('foo', $twig->render('func_array'));
     $this->assertEquals('bar', $twig->render('func_array_default'));
     $this->assertEquals('foo', $twig->render('func_array_named_args'));
     $this->assertEquals('foo', $twig->render('func_string'));
     $this->assertEquals('bar', $twig->render('func_string_default'));
     $this->assertEquals('foo', $twig->render('func_string_named_args'));
 }
开发者ID:bigbitecreative,项目名称:wordpress-git-content,代码行数:15,代码来源:EnvironmentTest.php

示例6: getTwigService

 protected function getTwigService()
 {
     $a = $this->get('request_stack');
     $b = new \Symfony\Bridge\Twig\AppVariable();
     $b->setEnvironment('prod');
     $b->setDebug(false);
     if ($this->has('security.token_storage')) {
         $b->setTokenStorage($this->get('security.token_storage', ContainerInterface::NULL_ON_INVALID_REFERENCE));
     }
     if ($this->has('request_stack')) {
         $b->setRequestStack($a);
     }
     $this->services['twig'] = $instance = new \Twig_Environment($this->get('twig.loader'), array('debug' => false, 'strict_variables' => false, 'exception_controller' => 'twig.controller.exception:showAction', 'form_themes' => array(0 => 'form_div_layout.html.twig'), 'autoescape' => 'name', 'cache' => __DIR__ . '/twig', 'charset' => 'UTF-8', 'paths' => array(), 'date' => array('format' => 'F j, Y H:i', 'interval_format' => '%d days', 'timezone' => NULL), 'number_format' => array('decimals' => 0, 'decimal_point' => '.', 'thousands_separator' => ',')));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\LogoutUrlExtension(${($_ = isset($this->services['security.logout_url_generator']) ? $this->services['security.logout_url_generator'] : $this->getSecurity_LogoutUrlGeneratorService()) && false ?: '_'}));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\SecurityExtension($this->get('security.authorization_checker', ContainerInterface::NULL_ON_INVALID_REFERENCE)));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\TranslationExtension($this->get('translator')));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\AssetExtension($this->get('assets.packages')));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\CodeExtension(${($_ = isset($this->services['debug.file_link_formatter']) ? $this->services['debug.file_link_formatter'] : $this->getDebug_FileLinkFormatterService()) && false ?: '_'}, $this->targetDirs[3] . '/app', 'UTF-8'));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\RoutingExtension($this->get('router')));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\YamlExtension());
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\StopwatchExtension($this->get('debug.stopwatch', ContainerInterface::NULL_ON_INVALID_REFERENCE), false));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\ExpressionExtension());
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\HttpKernelExtension());
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\HttpFoundationExtension($a, ${($_ = isset($this->services['router.request_context']) ? $this->services['router.request_context'] : $this->getRouter_RequestContextService()) && false ?: '_'}));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\FormExtension());
     $instance->addExtension($this->get('propel.twig.extension.syntax'));
     $instance->addGlobal('app', $b);
     $instance->addRuntimeLoader(new \Symfony\Bundle\TwigBundle\ContainerAwareRuntimeLoader($this, array('Symfony\\Bridge\\Twig\\Extension\\HttpKernelRuntime' => 'twig.runtime.httpkernel', 'Symfony\\Bridge\\Twig\\Form\\TwigRenderer' => 'twig.form.renderer'), $this->get('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE)));
     (new \Symfony\Bundle\TwigBundle\DependencyInjection\Configurator\EnvironmentConfigurator('F j, Y H:i', '%d days', NULL, 0, '.', ','))->configure($instance);
     return $instance;
 }
开发者ID:naldz,项目名称:cyberden,代码行数:31,代码来源:appProdProjectContainer.php


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