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


PHP Twig_Environment::compileSource方法代码示例

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


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

示例1: testGenerate

 /**
  * @dataProvider getGenerationTests
  */
 public function testGenerate($inputFile, $outputFile)
 {
     $env = new \Twig_Environment();
     $env->addExtension(new \Twig_Extension_Core());
     $env->addExtension(new TwigJsExtension());
     $env->setLoader(new \Twig_Loader_Filesystem(__DIR__ . '/Fixture/templates'));
     $env->setCompiler(new JsCompiler($env));
     $source = file_get_contents($inputFile);
     $this->assertEquals(file_get_contents($outputFile), $env->compileSource($source, $inputFile));
 }
开发者ID:raphydev,项目名称:onep,代码行数:13,代码来源:TemplateGenerationTest.php

示例2: testExtensionsAreNotInitializedWhenRenderingACompiledTemplate

 public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate()
 {
     $options = array('cache' => sys_get_temp_dir() . '/twig', 'auto_reload' => false, 'debug' => false);
     // force compilation
     $twig = new Twig_Environment($loader = new Twig_Loader_Array(array('index' => '{{ foo }}')), $options);
     $cache = $twig->getCacheFilename('index');
     if (!is_dir(dirname($cache))) {
         mkdir(dirname($cache), 0777, true);
     }
     file_put_contents($cache, $twig->compileSource('{{ foo }}', 'index'));
     // check that extensions won't be initialized when rendering a template that is already in the cache
     $twig = $this->getMockBuilder('Twig_Environment')->setConstructorArgs(array($loader, $options))->setMethods(array('initExtensions'))->getMock();
     $twig->expects($this->never())->method('initExtensions');
     // render template
     $output = $twig->render('index', array('foo' => 'bar'));
     $this->assertEquals('bar', $output);
     unlink($cache);
 }
开发者ID:JohnnyEstilles,项目名称:Twig,代码行数:18,代码来源:EnvironmentTest.php

示例3: RecursiveDirectoryIterator

require_once __DIR__ . '/../tests/bootstrap.php';
$_SERVER['TWIG_LIB'] = __DIR__ . '/../vendor/twig/twig/lib';
if (!isset($_SERVER['TWIG_LIB'])) {
    throw new \RuntimeException('$_SERVER["TWIG_LIB"] must be set.');
}
$env = new Twig_Environment();
$env->setLoader(new Twig_Loader_Filesystem(array(__DIR__ . '/../src-js/templates/twig')));
$env->addExtension(new Twig_Extension_Core());
$handler = new TwigJs\CompileRequestHandler($env, new TwigJs\JsCompiler($env));
foreach (new RecursiveDirectoryIterator(__DIR__ . '/../src-js/templates/twig', RecursiveDirectoryIterator::SKIP_DOTS) as $file) {
    if ('.twig' !== substr($file, -5)) {
        continue;
    }
    $request = new TwigJs\CompileRequest(basename($file), file_get_contents($file));
    file_put_contents(__DIR__ . '/../src-js/templates/js/' . basename($file, '.twig') . '.js', $handler->process($request));
    file_put_contents(__DIR__ . '/../src-js/templates/php/' . basename($file, '.twig') . '.php', $env->compileSource(file_get_contents($file), basename($file)));
}
// port over selected twig integration tests
$testsToPort = array('expressions/array');
$pathToFixtures = realpath($_SERVER['TWIG_LIB'] . '/../test/Twig/Tests/Fixtures');
$targetDir = realpath(__DIR__ . '/../src-js/templates/integration');
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pathToFixtures, RecursiveDirectoryIterator::SKIP_DOTS)) as $file) {
    if ('.test' !== substr($file, -5)) {
        continue;
    }
    $testName = str_replace(DIRECTORY_SEPARATOR, '/', substr($file, strlen($pathToFixtures) + 1, -5));
    if (!in_array($testName, $testsToPort, true)) {
        continue;
    }
    // parse test (copy&paste from twig's integrationTest.php)
    $test = file_get_contents($file->getRealpath());
开发者ID:raphydev,项目名称:onep,代码行数:31,代码来源:generate_test_templates.php

示例4: testExtensionsAreNotInitializedWhenRenderingACompiledTemplate

 public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate()
 {
     $cache = new Twig_Cache_Filesystem($dir = sys_get_temp_dir() . '/twig');
     $options = array('cache' => $cache, 'auto_reload' => false, 'debug' => false);
     // force compilation
     $twig = new Twig_Environment($loader = new Twig_Loader_Array(array('index' => '{{ foo }}')), $options);
     $key = $cache->generateKey('index', $twig->getTemplateClass('index'));
     $cache->write($key, $twig->compileSource(new Twig_Source('{{ foo }}', 'index')));
     // check that extensions won't be initialized when rendering a template that is already in the cache
     $twig = $this->getMockBuilder('Twig_Environment')->setConstructorArgs(array($loader, $options))->setMethods(array('initExtensions'))->getMock();
     $twig->expects($this->never())->method('initExtensions');
     // render template
     $output = $twig->render('index', array('foo' => 'bar'));
     $this->assertEquals('bar', $output);
     Twig_Tests_FilesystemHelper::removeDir($dir);
 }
开发者ID:bigbitecreative,项目名称:wordpress-git-content,代码行数:16,代码来源:EnvironmentTest.php

示例5: dumpCompiledTemplate

 /**
  * Only for debugging, dump the compiled template file to console and die
  *
  * @param string $template the name of the template in __DIR__/templates/
  */
 private function dumpCompiledTemplate($template)
 {
     $source = file_get_contents(__DIR__ . '/templates/' . $template);
     var_dump($this->twig->compileSource($source, $template));
     die;
 }
开发者ID:waifei,项目名称:createphp,代码行数:11,代码来源:CreatephpExtensionTest.php


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