Adopted composer autoload way

Split up classes into separate way, to allow autoloader to do it's work

Signed-off-by: Diederik de Groot <ddegroot@talon.nl>
This commit is contained in:
Diederik de Groot
2020-03-22 10:15:31 +01:00
parent fcf7e52370
commit 5064cb3e36
34 changed files with 1292 additions and 1023 deletions

View File

@@ -0,0 +1,66 @@
<?php
namespace PROVISION\ResolveCache;
use PROVISION\Utils as Utils;
class FileCache extends ResolveCache {
private $_isDirty = false;
private $_cache = array();
private $_cache_file = NULL;
function __construct($filename) {
$this->_cache_file = $filename;
if (file_exists($this->_cache_file)) {
$this->_cache = unserialize(file_get_contents($this->_cache_file));
$this->_isDirty = false;
} else {
$this->_isDirty = true;
}
}
function __destruct() {
if ($this->_isDirty) {
/*if (!is_writable($this->_cache_file)) {
log_error_and_throw("Could not write to file '".$this->_cache_file."' at Resolver::destruct");
}*/
if (!file_put_contents($this->_cache_file, serialize($this->_cache))) {
Utils::log_error_and_throw("Could not write to file '".$this->_cache_file."' at Resolver::destruct");
}
}
}
public function isDirty() {
return $this->_isDirty;
}
public function check($filename) {
return array_key_exists($filename, $this->_cache);
}
public function addFile($filename, $realpath) {
if ($this->check($filename))
Utils::log_error("Duplicate file:$filename"); /* should we prevent this ? */
$this->_cache[$filename] = $realpath;
$this->_isDirty =true;
}
public function removeFile($filename) {
if ($this->check($filename)) {
unset($this->_cache[$filename]);
$this->_isDirty = true;
}
}
public function getPath($filename) {
if ($this->check($filename)) {
return $this->_cache[$filename];
}
return false;
}
protected function printCache() {
print_r($this->_cache);
}
}
?>

View File

@@ -0,0 +1,24 @@
<?php
namespace PROVISION\ResolveCache;
abstract class ResolveCache {
abstract protected function addFile($filename, $realpath);
abstract protected function removeFile($filename);
abstract protected function check($filename);
abstract protected function getPath($filename);
}
/*
class SqliteCache extends ResolveCache {
function __construct() {
}
function __destruct() {
}
public function addFile($filename, $realpath);
public function removeFile($filename);
public function check($filename);
public function getPath($filename);
}
*/
?>