| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
class CJTIncludes implements ArrayAccess { |
| 10 |
|
| 11 |
/** |
| 12 |
* put your comment there... |
| 13 |
* |
| 14 |
* @var mixed |
| 15 |
*/ |
| 16 |
private $name; |
| 17 |
|
| 18 |
/** |
| 19 |
* put your comment there... |
| 20 |
* |
| 21 |
* @var mixed |
| 22 |
*/ |
| 23 |
protected $list; |
| 24 |
|
| 25 |
/** |
| 26 |
* put your comment there... |
| 27 |
* |
| 28 |
*/ |
| 29 |
public function __construct($name, $inits = array()) { |
| 30 |
$this->name = $name; |
| 31 |
// Copy all values! |
| 32 |
$this->setArray($inits); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* put your comment there... |
| 37 |
* |
| 38 |
* @param mixed $key |
| 39 |
* @param mixed $path |
| 40 |
*/ |
| 41 |
public function add($key, $path) { |
| 42 |
$this[$key] = $path; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* put your comment there... |
| 47 |
* |
| 48 |
* @param mixed $name |
| 49 |
*/ |
| 50 |
public static function addShared($name) { |
| 51 |
return self::$sharedList[$name] = new CJTIncludes(null); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* put your comment there... |
| 56 |
* |
| 57 |
*/ |
| 58 |
public function clear() { |
| 59 |
$this->list = array(); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* put your comment there... |
| 64 |
* |
| 65 |
* @param mixed $file |
| 66 |
*/ |
| 67 |
public function exists($file) { |
| 68 |
$result = array(); |
| 69 |
// Search all paths in reverve orders so override is allowed! |
| 70 |
end($this->list); |
| 71 |
do { |
| 72 |
$path = current($this->list); |
| 73 |
$fullPath = "{$path}/{$file}"; |
| 74 |
if (file_exists($fullPath)) { |
| 75 |
$result['key'] = key($this->list); |
| 76 |
$result['fullPath'] = $fullPath; |
| 77 |
break; |
| 78 |
} |
| 79 |
} while (prev($this->list)); |
| 80 |
return $result; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* put your comment there... |
| 85 |
* |
| 86 |
*/ |
| 87 |
public function hasPaths() { |
| 88 |
return !empty($this->list); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* put your comment there... |
| 93 |
* |
| 94 |
* @param mixed $file |
| 95 |
*/ |
| 96 |
public function import($file) { |
| 97 |
$result = false; |
| 98 |
if ($fileInfo = $this->exists($file)) { |
| 99 |
$result = require_once $fileInfo['fullPath']; |
| 100 |
} |
| 101 |
return $result; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* put your comment there... |
| 106 |
* |
| 107 |
* @param mixed $path |
| 108 |
*/ |
| 109 |
public function offsetExists($key): bool { |
| 110 |
return isset($this->list[$key]); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* put your comment there... |
| 115 |
* |
| 116 |
* @param mixed $path |
| 117 |
*/ |
| 118 |
public function offsetGet($key): bool { |
| 119 |
return $this->list[$key]; |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* put your comment there... |
| 124 |
* |
| 125 |
* @param mixed $path |
| 126 |
*/ |
| 127 |
public function offsetSet($key, $path): void { |
| 128 |
$this->list[$key] = $path; |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* put your comment there... |
| 133 |
* |
| 134 |
* @param mixed $path |
| 135 |
*/ |
| 136 |
public function offsetUnset($key): void { |
| 137 |
unset($this->list[$key]); |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* put your comment there... |
| 142 |
* |
| 143 |
* @param mixed $list |
| 144 |
*/ |
| 145 |
protected function setArray(& $list) { |
| 146 |
foreach ($list as $key => $path) { |
| 147 |
$this[$key] = $path; |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
} // End class. |
| 152 |
|