[core] Apply common indentation
All files are now using tabs for indentation
This commit is contained in:
parent
32ce2b6541
commit
62eec43980
19 changed files with 1365 additions and 1250 deletions
lib
134
lib/Cache.php
134
lib/Cache.php
|
@ -1,91 +1,93 @@
|
|||
<?php
|
||||
require_once(__DIR__ . '/CacheInterface.php');
|
||||
class Cache{
|
||||
class Cache {
|
||||
|
||||
static protected $dirCache;
|
||||
static protected $dirCache;
|
||||
|
||||
public function __construct(){
|
||||
throw new \LogicException('Please use ' . __CLASS__ . '::create for new object.');
|
||||
}
|
||||
public function __construct(){
|
||||
throw new \LogicException('Please use ' . __CLASS__ . '::create for new object.');
|
||||
}
|
||||
|
||||
static public function create($nameCache){
|
||||
if( !static::isValidNameCache($nameCache) ){
|
||||
throw new \InvalidArgumentException('Name cache must be at least one uppercase follow or not by alphanumeric or dash characters.');
|
||||
}
|
||||
static public function create($nameCache){
|
||||
if(!static::isValidNameCache($nameCache)){
|
||||
throw new \InvalidArgumentException('Name cache must be at least'
|
||||
. ' one uppercase follow or not by alphanumeric or dash characters.');
|
||||
}
|
||||
|
||||
$pathCache = self::getDir() . $nameCache . '.php';
|
||||
$pathCache = self::getDir() . $nameCache . '.php';
|
||||
|
||||
if( !file_exists($pathCache) ){
|
||||
throw new \Exception('The cache you looking for does not exist.');
|
||||
}
|
||||
if(!file_exists($pathCache)){
|
||||
throw new \Exception('The cache you looking for does not exist.');
|
||||
}
|
||||
|
||||
require_once $pathCache;
|
||||
require_once $pathCache;
|
||||
|
||||
return new $nameCache();
|
||||
}
|
||||
return new $nameCache();
|
||||
}
|
||||
|
||||
static public function setDir($dirCache){
|
||||
if( !is_string($dirCache) ){
|
||||
throw new \InvalidArgumentException('Dir cache must be a string.');
|
||||
}
|
||||
static public function setDir($dirCache){
|
||||
if(!is_string($dirCache)){
|
||||
throw new \InvalidArgumentException('Dir cache must be a string.');
|
||||
}
|
||||
|
||||
if( !file_exists($dirCache) ){
|
||||
throw new \Exception('Dir cache does not exist.');
|
||||
}
|
||||
if(!file_exists($dirCache)){
|
||||
throw new \Exception('Dir cache does not exist.');
|
||||
}
|
||||
|
||||
self::$dirCache = $dirCache;
|
||||
}
|
||||
self::$dirCache = $dirCache;
|
||||
}
|
||||
|
||||
static public function getDir(){
|
||||
$dirCache = self::$dirCache;
|
||||
static public function getDir(){
|
||||
$dirCache = self::$dirCache;
|
||||
|
||||
if( is_null($dirCache) ){
|
||||
throw new \LogicException(__CLASS__ . ' class need to know cache path !');
|
||||
}
|
||||
if(is_null($dirCache)){
|
||||
throw new \LogicException(__CLASS__ . ' class need to know cache path !');
|
||||
}
|
||||
|
||||
return $dirCache;
|
||||
}
|
||||
return $dirCache;
|
||||
}
|
||||
|
||||
static public function isValidNameCache($nameCache){
|
||||
return preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameCache);
|
||||
}
|
||||
static public function isValidNameCache($nameCache){
|
||||
return preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameCache);
|
||||
}
|
||||
|
||||
|
||||
static public function utf8_encode_deep(&$input) {
|
||||
if (is_string($input)) {
|
||||
$input = utf8_encode($input);
|
||||
} else if (is_array($input)) {
|
||||
foreach ($input as &$value) {
|
||||
Cache::utf8_encode_deep($value);
|
||||
}
|
||||
static public function utf8_encode_deep(&$input){
|
||||
if (is_string($input)){
|
||||
$input = utf8_encode($input);
|
||||
} elseif(is_array($input)){
|
||||
foreach($input as &$value){
|
||||
Cache::utf8_encode_deep($value);
|
||||
}
|
||||
|
||||
unset($value);
|
||||
} else if (is_object($input)) {
|
||||
$vars = array_keys(get_object_vars($input));
|
||||
unset($value);
|
||||
} elseif(is_object($input)){
|
||||
$vars = array_keys(get_object_vars($input));
|
||||
|
||||
foreach ($vars as $var) {
|
||||
Cache::utf8_encode_deep($input->$var);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($vars as $var){
|
||||
Cache::utf8_encode_deep($input->$var);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public function purge() {
|
||||
$cacheTimeLimit = time() - 60*60*24 ;
|
||||
|
||||
static public function purge(){
|
||||
$cacheTimeLimit = time() - 60*60*24;
|
||||
$cachePath = 'cache';
|
||||
if(file_exists($cachePath)) {
|
||||
$cacheIterator = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($cachePath),
|
||||
RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
foreach ($cacheIterator as $cacheFile) {
|
||||
if (in_array($cacheFile->getBasename(), array('.', '..')))
|
||||
continue;
|
||||
elseif ($cacheFile->isFile()) {
|
||||
if( filemtime($cacheFile->getPathname()) < $cacheTimeLimit )
|
||||
unlink( $cacheFile->getPathname() );
|
||||
}
|
||||
}
|
||||
if(file_exists($cachePath)){
|
||||
$cacheIterator = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($cachePath),
|
||||
RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
|
||||
foreach($cacheIterator as $cacheFile){
|
||||
if(in_array($cacheFile->getBasename(), array('.', '..')))
|
||||
continue;
|
||||
elseif($cacheFile->isFile()){
|
||||
if(filemtime($cacheFile->getPathname()) < $cacheTimeLimit)
|
||||
unlink($cacheFile->getPathname());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue