mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Fix #126: disable clearcachestats() by default in Fenom\Provider. Add method Fenom\Provider->setClearCachedStats() for enable clearcachestats()
This commit is contained in:
parent
7e8598ae3b
commit
4ca7ccb5e0
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,17 +1,9 @@
|
|||||||
.idea
|
.idea
|
||||||
vendor
|
vendor
|
||||||
coverage
|
|
||||||
build
|
build
|
||||||
composer.lock
|
composer.lock
|
||||||
composer.phar
|
composer.phar
|
||||||
tests/resources/compile/*
|
tests/resources/compile/*
|
||||||
!.gitkeep
|
!.gitkeep
|
||||||
tests/resources/template/*
|
tests/resources/template/*
|
||||||
!.gitkeep
|
sandbox/compiled/*
|
||||||
sandbox/compiled/*
|
|
||||||
!.gitkeep
|
|
||||||
benchmark/compile/*
|
|
||||||
benchmark/templates/inheritance/smarty
|
|
||||||
benchmark/templates/inheritance/twig
|
|
||||||
benchmark/sandbox/compiled/*
|
|
||||||
!.gitkeep
|
|
@ -874,7 +874,8 @@ class Fenom
|
|||||||
/**
|
/**
|
||||||
* Execute template and write result into stdout
|
* 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
|
* @param array $vars array of data for template
|
||||||
* @return Fenom\Render
|
* @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
|
* @param array $vars array of data for template
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
@ -897,7 +899,8 @@ class Fenom
|
|||||||
/**
|
/**
|
||||||
* Creates pipe-line of template's data to callback
|
* Creates pipe-line of template's data to callback
|
||||||
* @note Method not works correctly in old PHP 5.3.*
|
* @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 callable $callback template's data handler
|
||||||
* @param array $vars
|
* @param array $vars
|
||||||
* @param float $chunk amount of bytes of chunk
|
* @param float $chunk amount of bytes of chunk
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
namespace Fenom;
|
namespace Fenom;
|
||||||
|
|
||||||
use Fenom\ProviderInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base template provider
|
* Base template provider
|
||||||
* @author Ivan Shalganov
|
* @author Ivan Shalganov
|
||||||
@ -19,6 +17,8 @@ class Provider implements ProviderInterface
|
|||||||
{
|
{
|
||||||
private $_path;
|
private $_path;
|
||||||
|
|
||||||
|
protected $_clear_cache = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean directory from files
|
* 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
|
* Get source and mtime of template by name
|
||||||
* @param string $tpl
|
* @param string $tpl
|
||||||
@ -84,7 +93,9 @@ class Provider implements ProviderInterface
|
|||||||
public function getSource($tpl, &$time)
|
public function getSource($tpl, &$time)
|
||||||
{
|
{
|
||||||
$tpl = $this->_getTemplatePath($tpl);
|
$tpl = $this->_getTemplatePath($tpl);
|
||||||
clearstatcache(true, $tpl);
|
if($this->_clear_cache) {
|
||||||
|
clearstatcache(true, $tpl);
|
||||||
|
}
|
||||||
$time = filemtime($tpl);
|
$time = filemtime($tpl);
|
||||||
return file_get_contents($tpl);
|
return file_get_contents($tpl);
|
||||||
}
|
}
|
||||||
@ -96,7 +107,10 @@ class Provider implements ProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function getLastModified($tpl)
|
public function getLastModified($tpl)
|
||||||
{
|
{
|
||||||
clearstatcache(true, $tpl = $this->_getTemplatePath($tpl));
|
$tpl = $this->_getTemplatePath($tpl);
|
||||||
|
if($this->_clear_cache) {
|
||||||
|
clearstatcache(true, $tpl);
|
||||||
|
}
|
||||||
return filemtime($tpl);
|
return filemtime($tpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +172,10 @@ class Provider implements ProviderInterface
|
|||||||
public function verify(array $templates)
|
public function verify(array $templates)
|
||||||
{
|
{
|
||||||
foreach ($templates as $template => $mtime) {
|
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) {
|
if (@filemtime($template) !== $mtime) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,7 @@ class FenomTest extends \Fenom\TestCase
|
|||||||
public function testCheckMTime()
|
public function testCheckMTime()
|
||||||
{
|
{
|
||||||
$this->fenom->setOptions(Fenom::FORCE_COMPILE);
|
$this->fenom->setOptions(Fenom::FORCE_COMPILE);
|
||||||
|
$this->fenom->getProvider()->setClearCachedStats();
|
||||||
$this->tpl('custom.tpl', 'Custom template');
|
$this->tpl('custom.tpl', 'Custom template');
|
||||||
$this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array()));
|
$this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array()));
|
||||||
$tpl = $this->fenom->getTemplate('custom.tpl');
|
$tpl = $this->fenom->getTemplate('custom.tpl');
|
||||||
|
Loading…
Reference in New Issue
Block a user