本文整理汇总了PHP中Twig_Environment::getCacheFilename方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::getCacheFilename方法的具体用法?PHP Twig_Environment::getCacheFilename怎么用?PHP Twig_Environment::getCacheFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Environment
的用法示例。
在下文中一共展示了Twig_Environment::getCacheFilename方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addTemplate
public function addTemplate($path)
{
$this->environment->loadTemplate($path);
$this->templates[] = $this->environment->getCacheFilename($path);
}
示例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);
}
示例3: getCompiledPath
/**
* Get the path to the compiled version of a view.
*
* @param string $path
* @return string
*/
public function getCompiledPath($path)
{
return $this->twig->getCacheFilename($path);
}
示例4: _handleEvent
public static function _handleEvent($event)
{
$eventStart = microtime(true);
Kwf_Cache_Simple::resetZendCache();
//reset to re-fetch namespace
if (substr($event->filename, -4) == '.css' || substr($event->filename, -3) == '.js' || substr($event->filename, -9) == '.printcss' || substr($event->filename, -5) == '.scss') {
echo "asset modified\n";
if ($event instanceof Event\Modify) {
//there is no cache for individual files, scss cache is handled in Kwf_Assets_Dependency_File_Scss using mtime
$assetsType = substr($event->filename, strrpos($event->filename, '.') + 1);
if ($assetsType == 'scss') {
$assetsType = 'css';
}
self::_clearAssetsAll($assetsType);
if ($assetsType == 'js') {
self::_clearAssetsAll('defer.js');
}
} else {
if ($event instanceof Event\Create || $event instanceof Event\Delete || $event instanceof Event\Move) {
self::_clearAssetsDependencies();
$assetsType = substr($event->filename, strrpos($event->filename, '.') + 1);
if ($assetsType == 'scss') {
$assetsType = 'css';
}
self::_clearAssetsAll($assetsType);
if ($assetsType == 'js') {
self::_clearAssetsAll('defer.js');
}
}
}
} else {
if (self::_endsWith($event->filename, '/dependencies.ini')) {
if ($event instanceof Event\Modify) {
self::_clearAssetsDependencies();
self::_clearAssetsAll();
}
} else {
if (preg_match('#/config([^/]*)?\\.ini$#', $event->filename)) {
//config.ini, configPoi.ini, config.local.ini (in any directory)
if ($event instanceof Event\Modify) {
$section = call_user_func(array(Kwf_Setup::$configClass, 'getDefaultConfigSection'));
$cacheId = 'config_' . str_replace('-', '_', $section);
Kwf_Config_Cache::getInstance()->remove($cacheId);
echo "removed config cache\n";
$apcCacheId = $cacheId . getcwd();
$cacheIds = array($apcCacheId, $apcCacheId . 'mtime');
$simpleCacheStaticPrefixes = array('config-', 'configAr-');
if (Kwf_Util_Apc::isAvailable()) {
self::_clearApcCache(array('cacheIds' => $cacheIds, 'clearCacheSimpleStatic' => $simpleCacheStaticPrefixes));
echo "cleared apc config cache\n";
} else {
foreach ($simpleCacheStaticPrefixes as $i) {
Kwf_Cache_SimpleStatic::clear($i);
}
}
$cmd = Kwf_Config::getValue('server.phpCli') . " bootstrap.php clear-cache --type=setup";
exec($cmd, $out, $ret);
echo "cleared setup.php cache";
if ($ret) {
echo " [FAILED]";
}
echo "\n";
}
} else {
if (preg_match('#(Acl|MenuConfig)\\.php$#', $event->filename)) {
if ($event instanceof Event\Modify) {
Kwf_Acl::clearCache();
echo "cleared acl cache...\n";
}
} else {
if (self::_endsWith($event->filename, '.twig')) {
$loader = new Twig_Loader_Filesystem('.');
$twig = new Twig_Environment($loader, array('cache' => 'cache/twig'));
$cacheFile = $event->filename;
$cacheFile = substr($cacheFile, strlen(getcwd()) + 1);
$cacheFile = $twig->getCacheFilename($cacheFile);
if (file_exists($cacheFile)) {
unlink($cacheFile);
echo "cleared twig cache file '{$cacheFile}' for template '{$event->filename}'\n";
}
}
}
}
}
}
if (self::_startsWith($event->filename, getcwd() . '/components') || self::_startsWith($event->filename, getcwd() . '/theme') || self::_startsWith($event->filename, KWF_PATH . '/Kwc') || defined('VKWF_PATH') && self::_startsWith($event->filename, VKWF_PATH . '/Vkwc')) {
$cls = null;
foreach (explode(PATH_SEPARATOR, get_include_path()) as $ip) {
if (substr($ip, 0, 1) == '.') {
$ip = getcwd() . substr($ip, 1);
}
if (substr($ip, 0, 1) != '/') {
$ip = getcwd() . '/' . $ip;
}
if (self::_startsWith($event->filename, $ip)) {
$cls = str_replace('/', '_', substr($event->filename, strlen($ip) + 1, -4));
}
}
if (!$cls) {
echo "unknown component class?!\n";
//.........这里部分代码省略.........
示例5: str_purify
$config->set('HTML.Allowed', 'a[href],p,b,strong,u,i,em,q,blockquote,*[style]');
$_HTMLPurifier = new HTMLPurifier($config);
$twig->addFilter('purify', new Twig_Filter_Function('str_purify'));
function str_purify($dirty_html)
{
global $_HTMLPurifier;
return $_HTMLPurifier->purify($dirty_html);
}
function call_hook()
{
call_user_func_array(array(DatawrapperHooks::getInstance(), 'execute'), func_get_args());
}
$twig->addFunction('hook', new Twig_Function_Function('call_hook'));
// loae I18n extension for Twig
$twig->addExtension(new Twig_Extension_I18n());
// iterate over all your templates
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
if (substr($file, -5) == ".twig") {
// force compilation
$tmplPath = str_replace($tplDir . '/', '', $file);
$twig->loadTemplate($tmplPath);
$cacheFile = $twig->getCacheFilename($tmplPath);
$compiled = file_get_contents($cacheFile);
$outPath = $tmpDir . str_replace("/", "__", $tmplPath) . ".php";
if (substr($tmplPath, 0, 8) == 'plugins/') {
$outPath = $tmpDirPlugins . str_replace("/", "__", substr($tmplPath, 8)) . ".php";
}
file_put_contents($outPath, $compiled);
unlink($cacheFile);
}
}