Skip to content

Commit

Permalink
- improvement impement workaround for HHVM PHP incompatibillity faceb…
Browse files Browse the repository at this point in the history
  • Loading branch information
uwetews committed Jul 26, 2015
1 parent bb3dfc6 commit f9d9ca0
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 13 deletions.
3 changes: 3 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
 ===== 3.1.28-dev===== (xx.xx.2015)
26.07.2015
- improvement impement workaround for HHVM PHP incompatibillity https://github.com/facebook/hhvm/issues/4797

25.07.2015
- bugfix parser did hang on text starting <?something https://github.com/smarty-php/smarty/issues/74

Expand Down
2 changes: 1 addition & 1 deletion libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.28-dev/31';
const SMARTY_VERSION = '3.1.28-dev/32';

/**
* define variable scopes
Expand Down
5 changes: 3 additions & 2 deletions libs/sysplugins/smarty_cacheresource.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ abstract public function populateTimestamp(Smarty_Template_Cached $cached);
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param bool $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
* @return bool true or false if the cached content does not exist
*/
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null);
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false);

/**
* Write the rendered template output to cache
Expand Down
3 changes: 2 additions & 1 deletion libs/sysplugins/smarty_cacheresource_custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ public function populateTimestamp(Smarty_Template_Cached $cached)
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param bool $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
{
if (!$cached) {
$cached = $_template->cached;
Expand Down
3 changes: 2 additions & 1 deletion libs/sysplugins/smarty_cacheresource_keyvaluestore.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ public function populateTimestamp(Smarty_Template_Cached $cached)
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param bool $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
{
if (!$cached) {
$cached = $_template->cached;
Expand Down
10 changes: 7 additions & 3 deletions libs/sysplugins/smarty_internal_cacheresource_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,21 @@ public function populateTimestamp(Smarty_Template_Cached $cached)
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param bool $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
{
/** @var Smarty_Internal_Template $_smarty_tpl
* used in included file
*/
$_smarty_tpl = $_template;

return @include $_template->cached->filepath;
if (strpos(phpversion(), 'hhvm') !== false) {
return Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->cached->filepath);
} else {
return @include $_template->cached->filepath;
}
}

/**
Expand Down
31 changes: 31 additions & 0 deletions libs/sysplugins/smarty_internal_extension_hhvm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* Smarty Extension Hhvm
*
* include patch for modified compiled or cached templates
* HHVM does not check if file was modified when including same file multiple times
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Extension_Hhvm
{
/**
* @param \Smarty_Internal_Template $_template
* @param string $file file name
*
* @return mixed
*/
static function includeHhvm(Smarty_Internal_Template $_template, $file)
{
$_smarty_tpl = $_template;
$tmp_file = $_template->smarty->getCompileDir() . 'hhvm' .
str_replace(array('.', ','), '_', uniqid(rand(), true)) . '.php';
file_put_contents($tmp_file, file_get_contents($file));
$result = @include $tmp_file;
@unlink($tmp_file);
return $result;
}
}
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function render($merge_tpl_vars = false, $no_output_filter = true, $displ
$this->properties['tpl_function'] = $this->parent->properties['tpl_function'];
}
if (!$this->cached->processed) {
$this->cached->process($this);
$this->cached->process($this, true);
}
$this->smarty->compile_check = $compile_check;
$content = $this->getRenderedTemplateCode();
Expand Down
5 changes: 3 additions & 2 deletions libs/sysplugins/smarty_template_cached.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,11 @@ public function isCached(Smarty_Internal_Template $_template)
* Process cached template
*
* @param Smarty_Internal_Template $_template template object
* @param bool $update flag if called because cache update
*/
public function process(Smarty_Internal_Template $_template)
public function process(Smarty_Internal_Template $_template, $update = false)
{
if ($this->handler->process($_template, $this) === false) {
if ($this->handler->process($_template, $this, $update) === false) {
$this->valid = false;
}
if ($this->valid) {
Expand Down
12 changes: 10 additions & 2 deletions libs/sysplugins/smarty_template_compiled.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ public function process(Smarty_Internal_Template $_template)
if (function_exists('opcache_invalidate')) {
opcache_invalidate($_template->compiled->filepath);
}
include($_template->compiled->filepath);
if (strpos(phpversion(), 'hhvm') !== false) {
Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->compiled->filepath);
} else {
include($_template->compiled->filepath);
}
}
$_template->smarty->compile_check = $compileCheck;
} else {
Expand All @@ -188,7 +192,11 @@ public function process(Smarty_Internal_Template $_template)
if (function_exists('opcache_invalidate')) {
opcache_invalidate($_template->compiled->filepath);
}
include($_template->compiled->filepath);
if (strpos(phpversion(), 'hhvm') !== false) {
Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->compiled->filepath);
} else {
include($_template->compiled->filepath);
}
$_template->smarty->compile_check = $compileCheck;
}
}
Expand Down

0 comments on commit f9d9ca0

Please sign in to comment.