PSR12
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
@@ -16,62 +17,67 @@ namespace Domframework;
|
||||
*/
|
||||
class Cacheoutput
|
||||
{
|
||||
/** Record if the saving of pages is on going */
|
||||
private $saving = false;
|
||||
/** The called id */
|
||||
private $id = null;
|
||||
/** The called ttl */
|
||||
private $ttl = null;
|
||||
/** The cache object */
|
||||
private $cache = null;
|
||||
/** Current path at start due to lack of information in __destruct*/
|
||||
private $cacheCWD = null;
|
||||
/** Record if the saving of pages is on going */
|
||||
private $saving = false;
|
||||
/** The called id */
|
||||
private $id = null;
|
||||
/** The called ttl */
|
||||
private $ttl = null;
|
||||
/** The cache object */
|
||||
private $cache = null;
|
||||
/** Current path at start due to lack of information in __destruct*/
|
||||
private $cacheCWD = null;
|
||||
|
||||
/**
|
||||
@param string $id The cache identifier
|
||||
@param integer|null $ttl The cache Time to Leave in seconds (60s by
|
||||
default)
|
||||
@param string|null $method The cache method to use */
|
||||
public function __construct ($id, $ttl=60, $method="file")
|
||||
{
|
||||
$res = @include ("domframework/cache$method.php");
|
||||
if ($res === false)
|
||||
throw new \Exception (sprintf (dgettext ("domframework",
|
||||
"Unkwnown cache method : "), $method),
|
||||
500);
|
||||
$this->id = $id;
|
||||
$this->ttl = $ttl;
|
||||
$this->cacheCWD = getcwd();
|
||||
$cachemethod = "Cache$method";
|
||||
$this->cache = new $cachemethod ();
|
||||
if ($ttl === 0)
|
||||
$this->cache->nocache = 1;
|
||||
$res = $this->cache->read ($id);
|
||||
// If there is a cache : display it
|
||||
if ($res !== false)
|
||||
/**
|
||||
@param string $id The cache identifier
|
||||
@param integer|null $ttl The cache Time to Leave in seconds (60s by
|
||||
default)
|
||||
@param string|null $method The cache method to use */
|
||||
public function __construct($id, $ttl = 60, $method = "file")
|
||||
{
|
||||
foreach ($res["headers"] as $header)
|
||||
@header ($header);
|
||||
echo $res["content"];
|
||||
exit;
|
||||
$res = @include("domframework/cache$method.php");
|
||||
if ($res === false) {
|
||||
throw new \Exception(
|
||||
sprintf(dgettext(
|
||||
"domframework",
|
||||
"Unkwnown cache method : "
|
||||
), $method),
|
||||
500
|
||||
);
|
||||
}
|
||||
$this->id = $id;
|
||||
$this->ttl = $ttl;
|
||||
$this->cacheCWD = getcwd();
|
||||
$cachemethod = "Cache$method";
|
||||
$this->cache = new $cachemethod();
|
||||
if ($ttl === 0) {
|
||||
$this->cache->nocache = 1;
|
||||
}
|
||||
$res = $this->cache->read($id);
|
||||
// If there is a cache : display it
|
||||
if ($res !== false) {
|
||||
foreach ($res["headers"] as $header) {
|
||||
@header($header);
|
||||
}
|
||||
echo $res["content"];
|
||||
exit;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$this->saving = true;
|
||||
// The data are sent automatically
|
||||
}
|
||||
|
||||
ob_start ();
|
||||
$this->saving = true;
|
||||
// The data are sent automatically
|
||||
}
|
||||
|
||||
/** End of saving the data in cache */
|
||||
public function __destruct ()
|
||||
{
|
||||
// Force the path because it return to / in the destructor
|
||||
chdir ($this->cacheCWD);
|
||||
if ($this->saving === true)
|
||||
/** End of saving the data in cache */
|
||||
public function __destruct()
|
||||
{
|
||||
// Do the saving of the data
|
||||
$data = array ("content"=>ob_get_contents (),
|
||||
"headers"=>headers_list ());
|
||||
$this->cache->write ($this->id, $data, $this->ttl);
|
||||
// Force the path because it return to / in the destructor
|
||||
chdir($this->cacheCWD);
|
||||
if ($this->saving === true) {
|
||||
// Do the saving of the data
|
||||
$data = array("content" => ob_get_contents(),
|
||||
"headers" => headers_list());
|
||||
$this->cache->write($this->id, $data, $this->ttl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user