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