diff --git a/.gitignore b/.gitignore index 0a4e790..90bb033 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,9 @@ .idea vendor -coverage build composer.lock composer.phar tests/resources/compile/* !.gitkeep tests/resources/template/* -!.gitkeep -sandbox/compiled/* -!.gitkeep -benchmark/compile/* -benchmark/templates/inheritance/smarty -benchmark/templates/inheritance/twig -benchmark/sandbox/compiled/* -!.gitkeep \ No newline at end of file +sandbox/compiled/* \ No newline at end of file diff --git a/src/Fenom.php b/src/Fenom.php index f8e2cc3..a8779e4 100644 --- a/src/Fenom.php +++ b/src/Fenom.php @@ -874,7 +874,8 @@ class Fenom /** * Execute template and write result into stdout * - * @param string $template name of template + * @param string|array $template name of template. + * If it is array of names of templates they will be extended from left to right. * @param array $vars array of data for template * @return Fenom\Render */ @@ -885,7 +886,8 @@ class Fenom /** * - * @param string $template name of template + * @param string|array $template name of template. + * If it is array of names of templates they will be extended from left to right. * @param array $vars array of data for template * @return mixed */ @@ -897,7 +899,8 @@ class Fenom /** * Creates pipe-line of template's data to callback * @note Method not works correctly in old PHP 5.3.* - * @param string $template name of the template + * @param string|array $template name of the template. + * If it is array of names of templates they will be extended from left to right. * @param callable $callback template's data handler * @param array $vars * @param float $chunk amount of bytes of chunk diff --git a/src/Fenom/Provider.php b/src/Fenom/Provider.php index 6ea55db..e9b28fd 100644 --- a/src/Fenom/Provider.php +++ b/src/Fenom/Provider.php @@ -9,8 +9,6 @@ */ namespace Fenom; -use Fenom\ProviderInterface; - /** * Base template provider * @author Ivan Shalganov @@ -19,6 +17,8 @@ class Provider implements ProviderInterface { private $_path; + protected $_clear_cache = false; + /** * Clean directory from files * @@ -75,6 +75,15 @@ class Provider implements ProviderInterface } } + /** + * Disable PHP cache for files. PHP cache some operations with files then script works. + * @see http://php.net/manual/en/function.clearstatcache.php + * @param bool $status + */ + public function setClearCachedStats($status = true) { + $this->_clear_cache = $status; + } + /** * Get source and mtime of template by name * @param string $tpl @@ -84,7 +93,9 @@ class Provider implements ProviderInterface public function getSource($tpl, &$time) { $tpl = $this->_getTemplatePath($tpl); - clearstatcache(true, $tpl); + if($this->_clear_cache) { + clearstatcache(true, $tpl); + } $time = filemtime($tpl); return file_get_contents($tpl); } @@ -96,7 +107,10 @@ class Provider implements ProviderInterface */ public function getLastModified($tpl) { - clearstatcache(true, $tpl = $this->_getTemplatePath($tpl)); + $tpl = $this->_getTemplatePath($tpl); + if($this->_clear_cache) { + clearstatcache(true, $tpl); + } return filemtime($tpl); } @@ -158,7 +172,10 @@ class Provider implements ProviderInterface public function verify(array $templates) { foreach ($templates as $template => $mtime) { - clearstatcache(true, $template = $this->_path . '/' . $template); + $template = $this->_path . '/' . $template; + if($this->_clear_cache) { + clearstatcache(true, $template); + } if (@filemtime($template) !== $mtime) { return false; } diff --git a/tests/cases/FenomTest.php b/tests/cases/FenomTest.php index e49b66f..b4076c7 100644 --- a/tests/cases/FenomTest.php +++ b/tests/cases/FenomTest.php @@ -96,6 +96,7 @@ class FenomTest extends \Fenom\TestCase public function testCheckMTime() { $this->fenom->setOptions(Fenom::FORCE_COMPILE); + $this->fenom->getProvider()->setClearCachedStats(); $this->tpl('custom.tpl', 'Custom template'); $this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array())); $tpl = $this->fenom->getTemplate('custom.tpl');