@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | * @access public |
| 98 | 98 | * @param string $sName name of the session |
| 99 | - * @return mixed |
|
| 99 | + * @return boolean |
|
| 100 | 100 | */ |
| 101 | 101 | public function delete(string $sName) |
| 102 | 102 | { |
@@ -107,7 +107,6 @@ discard block |
||
| 107 | 107 | * flush the cache |
| 108 | 108 | * |
| 109 | 109 | * @access public |
| 110 | - * @param string $sName name of the session |
|
| 111 | 110 | * @return mixed |
| 112 | 111 | */ |
| 113 | 112 | public function flush() |
@@ -120,7 +119,7 @@ discard block |
||
| 120 | 119 | * |
| 121 | 120 | * @access public |
| 122 | 121 | * @param string $sName name of the session |
| 123 | - * @return mixed |
|
| 122 | + * @return string |
|
| 124 | 123 | */ |
| 125 | 124 | private function _getSubDirectory($sName) |
| 126 | 125 | { |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @param int $iTimeout expiration of cache |
| 75 | 75 | * @return mixed |
| 76 | 76 | */ |
| 77 | - public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
|
| 77 | + public function get(string $sName, int&$iFlags = null, int $iTimeout = 0) |
|
| 78 | 78 | { |
| 79 | 79 | if ($iTimeout > 0 && file_exists($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac') |
| 80 | 80 | && time() - filemtime($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac') > $iTimeout) { |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | if (file_exists($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac')) { |
| 86 | 86 | |
| 87 | - return unserialize(file_get_contents($this->_sFolder . $this->_getSubDirectory($sName) . md5($sName) . '.fil.cac')); |
|
| 87 | + return unserialize(file_get_contents($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac')); |
|
| 88 | 88 | } else { |
| 89 | 89 | |
| 90 | 90 | return false; |
@@ -30,125 +30,125 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class File implements CacheInterface |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * var containe this folder of cache |
|
| 35 | - * |
|
| 36 | - * @access private |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - private $_sFolder = ''; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * constructor |
|
| 43 | - * |
|
| 44 | - * @access public |
|
| 45 | - */ |
|
| 46 | - public function __construct() |
|
| 47 | - { |
|
| 48 | - $this->_sFolder = str_replace('bundles'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Cache', CACHE_DIR, __DIR__).DIRECTORY_SEPARATOR; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * set a value |
|
| 53 | - * |
|
| 54 | - * @access public |
|
| 55 | - * @param string $sName name of the session |
|
| 56 | - * @param mixed $mValue value of this sesion var |
|
| 57 | - * @param int $iFlag flags |
|
| 58 | - * @param int $iExpire expiration of cache |
|
| 59 | - * @return \Venus\lib\Cache\File |
|
| 60 | - */ |
|
| 61 | - public function set(string $sName, $mValue, int $iFlag, int $iExpire) |
|
| 62 | - { |
|
| 63 | - file_put_contents($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac', serialize($mValue)); |
|
| 64 | - return $this; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * get a value |
|
| 69 | - * |
|
| 70 | - * @access public |
|
| 71 | - * @param string $sName name of the session |
|
| 72 | - * @param int $iFlags flags |
|
| 73 | - * @param int $iTimeout expiration of cache |
|
| 74 | - * @return mixed |
|
| 75 | - */ |
|
| 76 | - public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
|
| 77 | - { |
|
| 78 | - if ($iTimeout > 0 && file_exists($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac') |
|
| 79 | - && time() - filemtime($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac') > $iTimeout) { |
|
| 80 | - |
|
| 81 | - unlink($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - if (file_exists($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac')) { |
|
| 85 | - |
|
| 86 | - return unserialize(file_get_contents($this->_sFolder . $this->_getSubDirectory($sName) . md5($sName) . '.fil.cac')); |
|
| 87 | - } else { |
|
| 88 | - |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * delete a value |
|
| 95 | - * |
|
| 96 | - * @access public |
|
| 97 | - * @param string $sName name of the session |
|
| 98 | - * @return mixed |
|
| 99 | - */ |
|
| 100 | - public function delete(string $sName) |
|
| 101 | - { |
|
| 102 | - return unlink($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac'); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * flush the cache |
|
| 107 | - * |
|
| 108 | - * @access public |
|
| 109 | - * @param string $sName name of the session |
|
| 110 | - * @return mixed |
|
| 111 | - */ |
|
| 112 | - public function flush() |
|
| 113 | - { |
|
| 114 | - $this->_removeDirectory($this->_sFolder); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * |
|
| 119 | - * |
|
| 120 | - * @access public |
|
| 121 | - * @param string $sName name of the session |
|
| 122 | - * @return mixed |
|
| 123 | - */ |
|
| 124 | - private function _getSubDirectory($sName) |
|
| 125 | - { |
|
| 126 | - if (!file_exists($this->_sFolder.substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2))) { |
|
| 127 | - |
|
| 128 | - mkdir($this->_sFolder.substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2), 0777, true); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2).DIRECTORY_SEPARATOR; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * remove a directory recursivly |
|
| 136 | - * |
|
| 137 | - * @access private |
|
| 138 | - * @param string $sName nom du répertoire |
|
| 139 | - * @return void |
|
| 140 | - */ |
|
| 141 | - private function _removeDirectory($sName) |
|
| 142 | - { |
|
| 143 | - if ($rDirectory = opendir($sName)) { |
|
| 144 | - |
|
| 145 | - while (($sFile = readdir($rDirectory)) !== false) { |
|
| 146 | - |
|
| 147 | - if ($sFile > '0' && filetype($sName.$sFile) == "file") { unlink($sName.$sFile); } elseif ($sFile > '0' && filetype($sName.$sFile) == "dir") { remove_dir($sName.$sFile."\\"); } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - closedir($rDirectory); |
|
| 151 | - rmdir($sName); |
|
| 152 | - } |
|
| 153 | - } |
|
| 33 | + /** |
|
| 34 | + * var containe this folder of cache |
|
| 35 | + * |
|
| 36 | + * @access private |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + private $_sFolder = ''; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * constructor |
|
| 43 | + * |
|
| 44 | + * @access public |
|
| 45 | + */ |
|
| 46 | + public function __construct() |
|
| 47 | + { |
|
| 48 | + $this->_sFolder = str_replace('bundles'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Cache', CACHE_DIR, __DIR__).DIRECTORY_SEPARATOR; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * set a value |
|
| 53 | + * |
|
| 54 | + * @access public |
|
| 55 | + * @param string $sName name of the session |
|
| 56 | + * @param mixed $mValue value of this sesion var |
|
| 57 | + * @param int $iFlag flags |
|
| 58 | + * @param int $iExpire expiration of cache |
|
| 59 | + * @return \Venus\lib\Cache\File |
|
| 60 | + */ |
|
| 61 | + public function set(string $sName, $mValue, int $iFlag, int $iExpire) |
|
| 62 | + { |
|
| 63 | + file_put_contents($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac', serialize($mValue)); |
|
| 64 | + return $this; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * get a value |
|
| 69 | + * |
|
| 70 | + * @access public |
|
| 71 | + * @param string $sName name of the session |
|
| 72 | + * @param int $iFlags flags |
|
| 73 | + * @param int $iTimeout expiration of cache |
|
| 74 | + * @return mixed |
|
| 75 | + */ |
|
| 76 | + public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
|
| 77 | + { |
|
| 78 | + if ($iTimeout > 0 && file_exists($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac') |
|
| 79 | + && time() - filemtime($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac') > $iTimeout) { |
|
| 80 | + |
|
| 81 | + unlink($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + if (file_exists($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac')) { |
|
| 85 | + |
|
| 86 | + return unserialize(file_get_contents($this->_sFolder . $this->_getSubDirectory($sName) . md5($sName) . '.fil.cac')); |
|
| 87 | + } else { |
|
| 88 | + |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * delete a value |
|
| 95 | + * |
|
| 96 | + * @access public |
|
| 97 | + * @param string $sName name of the session |
|
| 98 | + * @return mixed |
|
| 99 | + */ |
|
| 100 | + public function delete(string $sName) |
|
| 101 | + { |
|
| 102 | + return unlink($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac'); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * flush the cache |
|
| 107 | + * |
|
| 108 | + * @access public |
|
| 109 | + * @param string $sName name of the session |
|
| 110 | + * @return mixed |
|
| 111 | + */ |
|
| 112 | + public function flush() |
|
| 113 | + { |
|
| 114 | + $this->_removeDirectory($this->_sFolder); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * |
|
| 119 | + * |
|
| 120 | + * @access public |
|
| 121 | + * @param string $sName name of the session |
|
| 122 | + * @return mixed |
|
| 123 | + */ |
|
| 124 | + private function _getSubDirectory($sName) |
|
| 125 | + { |
|
| 126 | + if (!file_exists($this->_sFolder.substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2))) { |
|
| 127 | + |
|
| 128 | + mkdir($this->_sFolder.substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2), 0777, true); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2).DIRECTORY_SEPARATOR; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * remove a directory recursivly |
|
| 136 | + * |
|
| 137 | + * @access private |
|
| 138 | + * @param string $sName nom du répertoire |
|
| 139 | + * @return void |
|
| 140 | + */ |
|
| 141 | + private function _removeDirectory($sName) |
|
| 142 | + { |
|
| 143 | + if ($rDirectory = opendir($sName)) { |
|
| 144 | + |
|
| 145 | + while (($sFile = readdir($rDirectory)) !== false) { |
|
| 146 | + |
|
| 147 | + if ($sFile > '0' && filetype($sName.$sFile) == "file") { unlink($sName.$sFile); } elseif ($sFile > '0' && filetype($sName.$sFile) == "dir") { remove_dir($sName.$sFile."\\"); } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + closedir($rDirectory); |
|
| 151 | + rmdir($sName); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | 154 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * flush the cache |
| 94 | 94 | * |
| 95 | 95 | * @access public |
| 96 | - * @return mixed |
|
| 96 | + * @return boolean |
|
| 97 | 97 | */ |
| 98 | 98 | public function flush() |
| 99 | 99 | { |
@@ -129,9 +129,8 @@ discard block |
||
| 129 | 129 | * @access public |
| 130 | 130 | * @param string $sName name of the session |
| 131 | 131 | * @param mixed $mValue value of this sesion var |
| 132 | - * @param int $iFlag unused |
|
| 133 | 132 | * @param int $iExpire expiration of cache |
| 134 | - * @return mixed |
|
| 133 | + * @return Apc |
|
| 135 | 134 | */ |
| 136 | 135 | public function add(string $sName, $mValue, int $iExpire = false) |
| 137 | 136 | { |
@@ -32,109 +32,109 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class Redis extends RealRedis implements CacheInterface |
| 34 | 34 | { |
| 35 | - /** |
|
| 36 | - * constructor with the connection to Redis |
|
| 37 | - * |
|
| 38 | - * @access public |
|
| 39 | - * @param $oConf |
|
| 40 | - * @throws \Exception |
|
| 41 | - * @internal param string $sName name of the session |
|
| 42 | - * @internal param int $iFlags flags |
|
| 43 | - * @internal param int $iTimeout expiration of cache |
|
| 44 | - */ |
|
| 45 | - public function __construct($oConf) |
|
| 46 | - { |
|
| 47 | - if (!$this->connect($oConf->host, $oConf->port)) { |
|
| 35 | + /** |
|
| 36 | + * constructor with the connection to Redis |
|
| 37 | + * |
|
| 38 | + * @access public |
|
| 39 | + * @param $oConf |
|
| 40 | + * @throws \Exception |
|
| 41 | + * @internal param string $sName name of the session |
|
| 42 | + * @internal param int $iFlags flags |
|
| 43 | + * @internal param int $iTimeout expiration of cache |
|
| 44 | + */ |
|
| 45 | + public function __construct($oConf) |
|
| 46 | + { |
|
| 47 | + if (!$this->connect($oConf->host, $oConf->port)) { |
|
| 48 | 48 | |
| 49 | - throw new \Exception('Redis server unavailable'); |
|
| 50 | - } |
|
| 49 | + throw new \Exception('Redis server unavailable'); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - // Select the REDIS db index |
|
| 53 | - $this->select($oConf->index); |
|
| 54 | - } |
|
| 52 | + // Select the REDIS db index |
|
| 53 | + $this->select($oConf->index); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * get a value |
|
| 58 | - * |
|
| 59 | - * @access public |
|
| 60 | - * @param string $sName name of the session |
|
| 61 | - * @param int $iFlags flags |
|
| 62 | - * @param int $iTimeout expiration of cache |
|
| 63 | - * @return mixed |
|
| 64 | - */ |
|
| 65 | - public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
|
| 66 | - { |
|
| 67 | - return parent::get($sName); |
|
| 68 | - } |
|
| 56 | + /** |
|
| 57 | + * get a value |
|
| 58 | + * |
|
| 59 | + * @access public |
|
| 60 | + * @param string $sName name of the session |
|
| 61 | + * @param int $iFlags flags |
|
| 62 | + * @param int $iTimeout expiration of cache |
|
| 63 | + * @return mixed |
|
| 64 | + */ |
|
| 65 | + public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
|
| 66 | + { |
|
| 67 | + return parent::get($sName); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * set a value |
|
| 72 | - * |
|
| 73 | - * @access public |
|
| 74 | - * @param string $sName name of the session |
|
| 75 | - * @param mixed $mValue value of this sesion var |
|
| 76 | - * @param int $iFlag unused |
|
| 77 | - * @param int $iExpire expiration of cache |
|
| 78 | - * @return \Venus\lib\Cache\Apc |
|
| 79 | - */ |
|
| 80 | - public function set(string $sName, $mValue, int $iFlag = 0, int $iExpire = false) |
|
| 81 | - { |
|
| 82 | - if ($iExpire === false) { |
|
| 70 | + /** |
|
| 71 | + * set a value |
|
| 72 | + * |
|
| 73 | + * @access public |
|
| 74 | + * @param string $sName name of the session |
|
| 75 | + * @param mixed $mValue value of this sesion var |
|
| 76 | + * @param int $iFlag unused |
|
| 77 | + * @param int $iExpire expiration of cache |
|
| 78 | + * @return \Venus\lib\Cache\Apc |
|
| 79 | + */ |
|
| 80 | + public function set(string $sName, $mValue, int $iFlag = 0, int $iExpire = false) |
|
| 81 | + { |
|
| 82 | + if ($iExpire === false) { |
|
| 83 | 83 | |
| 84 | - return parent::set($sName, $mValue); |
|
| 85 | - } |
|
| 86 | - else { |
|
| 84 | + return parent::set($sName, $mValue); |
|
| 85 | + } |
|
| 86 | + else { |
|
| 87 | 87 | |
| 88 | - return parent::setex($sName, $iExpire, $mValue); |
|
| 89 | - } |
|
| 90 | - } |
|
| 88 | + return parent::setex($sName, $iExpire, $mValue); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * flush the cache |
|
| 94 | - * |
|
| 95 | - * @access public |
|
| 96 | - * @return mixed |
|
| 97 | - */ |
|
| 98 | - public function flush() |
|
| 99 | - { |
|
| 100 | - return false; |
|
| 101 | - } |
|
| 92 | + /** |
|
| 93 | + * flush the cache |
|
| 94 | + * |
|
| 95 | + * @access public |
|
| 96 | + * @return mixed |
|
| 97 | + */ |
|
| 98 | + public function flush() |
|
| 99 | + { |
|
| 100 | + return false; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * delete a value |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @param string $sName name of the session |
|
| 108 | - * @return mixed |
|
| 109 | - */ |
|
| 110 | - public function delete(string $sName) |
|
| 111 | - { |
|
| 112 | - return $this->del($sName); |
|
| 113 | - } |
|
| 103 | + /** |
|
| 104 | + * delete a value |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @param string $sName name of the session |
|
| 108 | + * @return mixed |
|
| 109 | + */ |
|
| 110 | + public function delete(string $sName) |
|
| 111 | + { |
|
| 112 | + return $this->del($sName); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * close the redis connecction |
|
| 117 | - * |
|
| 118 | - * @access public |
|
| 119 | - * @return mixed |
|
| 120 | - */ |
|
| 121 | - public function __sleep() |
|
| 122 | - { |
|
| 123 | - $this->close(); |
|
| 124 | - } |
|
| 115 | + /** |
|
| 116 | + * close the redis connecction |
|
| 117 | + * |
|
| 118 | + * @access public |
|
| 119 | + * @return mixed |
|
| 120 | + */ |
|
| 121 | + public function __sleep() |
|
| 122 | + { |
|
| 123 | + $this->close(); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * add |
|
| 128 | - * |
|
| 129 | - * @access public |
|
| 130 | - * @param string $sName name of the session |
|
| 131 | - * @param mixed $mValue value of this sesion var |
|
| 132 | - * @param int $iFlag unused |
|
| 133 | - * @param int $iExpire expiration of cache |
|
| 134 | - * @return mixed |
|
| 135 | - */ |
|
| 136 | - public function add(string $sName, $mValue, int $iExpire = false) |
|
| 137 | - { |
|
| 138 | - return $this->set($sName, $mValue, 0, $iExpire); |
|
| 139 | - } |
|
| 126 | + /** |
|
| 127 | + * add |
|
| 128 | + * |
|
| 129 | + * @access public |
|
| 130 | + * @param string $sName name of the session |
|
| 131 | + * @param mixed $mValue value of this sesion var |
|
| 132 | + * @param int $iFlag unused |
|
| 133 | + * @param int $iExpire expiration of cache |
|
| 134 | + * @return mixed |
|
| 135 | + */ |
|
| 136 | + public function add(string $sName, $mValue, int $iExpire = false) |
|
| 137 | + { |
|
| 138 | + return $this->set($sName, $mValue, 0, $iExpire); |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -62,7 +62,7 @@ |
||
| 62 | 62 | * @param int $iTimeout expiration of cache |
| 63 | 63 | * @return mixed |
| 64 | 64 | */ |
| 65 | - public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
|
| 65 | + public function get(string $sName, int&$iFlags = null, int $iTimeout = 0) |
|
| 66 | 66 | { |
| 67 | 67 | return parent::get($sName); |
| 68 | 68 | } |
@@ -60,8 +60,7 @@ |
||
| 60 | 60 | echo "\n\n"; |
| 61 | 61 | echo " > Check realized on ".$options['a']; |
| 62 | 62 | echo "\n\n"; |
| 63 | - } |
|
| 64 | - else { |
|
| 63 | + } else { |
|
| 65 | 64 | echo "\n\n"; |
| 66 | 65 | echo Bash::setBackground(" ", 'red'); |
| 67 | 66 | echo Bash::setBackground(" [WARNING] A web server is not used ", 'red'); |
@@ -118,8 +118,7 @@ |
||
| 118 | 118 | */ |
| 119 | 119 | public function redirect(string $sUrl, int $iHttpCode = 301) |
| 120 | 120 | { |
| 121 | - if ($iHttpCode === 301) { header('Status: 301 Moved Permanently', false, 301); } |
|
| 122 | - else if ($iHttpCode === 302) { header('Status: Moved Temporarily', false, 301); } |
|
| 121 | + if ($iHttpCode === 301) { header('Status: 301 Moved Permanently', false, 301); } else if ($iHttpCode === 302) { header('Status: Moved Temporarily', false, 301); } |
|
| 123 | 122 | |
| 124 | 123 | header('Location: '.$sUrl); |
| 125 | 124 | exit; |
@@ -43,138 +43,138 @@ |
||
| 43 | 43 | abstract class Controller extends Mother |
| 44 | 44 | { |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Cache to know if a model was initialize or not because we must initialize it just one time by script |
|
| 48 | - * |
|
| 49 | - * @access private |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - private static $_aInitialize = array(); |
|
| 46 | + /** |
|
| 47 | + * Cache to know if a model was initialize or not because we must initialize it just one time by script |
|
| 48 | + * |
|
| 49 | + * @access private |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + private static $_aInitialize = array(); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Constructor |
|
| 56 | - * |
|
| 57 | - * @access public |
|
| 58 | - */ |
|
| 59 | - public function __construct() |
|
| 60 | - { |
|
| 61 | - $aClass = explode('\\', get_called_class()); |
|
| 62 | - $sClassName = $aClass[count($aClass) - 1]; |
|
| 63 | - $sNamespaceName = preg_replace('/\\\\'.$sClassName.'$/', '', get_called_class()); |
|
| 64 | - |
|
| 65 | - if (isset($sClassName)) { |
|
| 66 | - |
|
| 67 | - $sNamespaceBaseName = str_replace('\Controller', '', $sNamespaceName); |
|
| 68 | - $sDefaultModel = $sNamespaceBaseName.'\Model\\'.$sClassName; |
|
| 69 | - $sDefaultView = str_replace('\\', DIRECTORY_SEPARATOR, str_replace('Venus\\', '\\', $sNamespaceBaseName)).DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$sClassName.'.tpl'; |
|
| 70 | - $sDefaultLayout = str_replace('\\', DIRECTORY_SEPARATOR, str_replace('Venus\\', '\\', $sNamespaceBaseName)).DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.'Layout.tpl'; |
|
| 71 | - |
|
| 72 | - $this->model = function() use ($sDefaultModel) { return new $sDefaultModel; }; |
|
| 73 | - |
|
| 74 | - $this->view = function() use ($sDefaultView) { return Vendor::getVendor('Apollina\Template', $sDefaultView); }; |
|
| 75 | - |
|
| 76 | - $this->layout = function() use ($sDefaultLayout) { return Vendor::getVendor('Apollina\Template', $sDefaultLayout, true); }; |
|
| 77 | - |
|
| 78 | - $this->layout->assign('model', $sDefaultView); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $this->form = function() { return new Form(); }; |
|
| 82 | - $this->security = function() { return new Security(); }; |
|
| 83 | - $this->router = function() { return new Router; }; |
|
| 84 | - $this->mail = function() { return new Mail; }; |
|
| 85 | - $this->session = function() { return new Session; }; |
|
| 86 | - $this->translator = function() { return new I18n; }; |
|
| 87 | - $this->url = function() { return new UrlManager; }; |
|
| 88 | - $this->cookie = function() { return new Cookie; }; |
|
| 89 | - $this->di = function() { return new Di; }; |
|
| 90 | - $this->request = function() { return new Request; }; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Trigger on a model to initialize it. You could fill entity with it. |
|
| 94 | - */ |
|
| 95 | - if (method_exists(get_called_class(), 'initialize')) { |
|
| 96 | - |
|
| 97 | - if (!isset(self::$_aInitialize[get_called_class()])) { |
|
| 98 | - |
|
| 99 | - static::initialize(); |
|
| 100 | - self::$_aInitialize[get_called_class()] = true; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Trigger on a model to initialize it every time you construct it |
|
| 106 | - */ |
|
| 107 | - if (method_exists(get_called_class(), 'onConstruct')) { static::onConstruct(); } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * redirection HTTP |
|
| 112 | - * |
|
| 113 | - * @access public |
|
| 114 | - * @param string $sUrl url for the redirection |
|
| 115 | - * @param int $iHttpCode code of the http request |
|
| 116 | - * @return void |
|
| 117 | - */ |
|
| 118 | - public function redirect(string $sUrl, int $iHttpCode = 301) |
|
| 119 | - { |
|
| 120 | - if ($iHttpCode === 301) { header('Status: 301 Moved Permanently', false, 301); } |
|
| 121 | - else if ($iHttpCode === 302) { header('Status: Moved Temporarily', false, 301); } |
|
| 122 | - |
|
| 123 | - header('Location: '.$sUrl); |
|
| 124 | - exit; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * call an other action as you call action with URL/Cli |
|
| 129 | - * |
|
| 130 | - * @access public |
|
| 131 | - * @param string $sUri uri for the redirection |
|
| 132 | - * @param array $aParams parameters |
|
| 133 | - * @return void |
|
| 134 | - */ |
|
| 135 | - public function forward(string $sUri, array $aParams = array()) |
|
| 136 | - { |
|
| 137 | - $this->router->runByFoward($sUri, $aParams); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * call the 404 Not Found page |
|
| 142 | - * |
|
| 143 | - * @access public |
|
| 144 | - * @return void |
|
| 145 | - */ |
|
| 146 | - public function notFound() |
|
| 147 | - { |
|
| 148 | - $$this->router->runHttpErrorPage(404); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * call the 403 Forbidden page |
|
| 153 | - * |
|
| 154 | - * @access public |
|
| 155 | - * @return void |
|
| 156 | - */ |
|
| 157 | - public function forbidden() |
|
| 158 | - { |
|
| 159 | - $$this->router->runHttpErrorPage(403); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * get a property |
|
| 164 | - * |
|
| 165 | - * @access public |
|
| 166 | - * @param unknown_type $mKey |
|
| 167 | - * @return void |
|
| 168 | - */ |
|
| 169 | - public function __get($mKey) |
|
| 170 | - { |
|
| 171 | - if (isset($this->di) && property_exists($this, 'di')) { |
|
| 172 | - |
|
| 173 | - $mDi = $this->di->get($mKey); |
|
| 174 | - |
|
| 175 | - if (isset($mDi) && $mDi !== false) { return $mDi; } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return parent::__get($mKey); |
|
| 179 | - } |
|
| 54 | + /** |
|
| 55 | + * Constructor |
|
| 56 | + * |
|
| 57 | + * @access public |
|
| 58 | + */ |
|
| 59 | + public function __construct() |
|
| 60 | + { |
|
| 61 | + $aClass = explode('\\', get_called_class()); |
|
| 62 | + $sClassName = $aClass[count($aClass) - 1]; |
|
| 63 | + $sNamespaceName = preg_replace('/\\\\'.$sClassName.'$/', '', get_called_class()); |
|
| 64 | + |
|
| 65 | + if (isset($sClassName)) { |
|
| 66 | + |
|
| 67 | + $sNamespaceBaseName = str_replace('\Controller', '', $sNamespaceName); |
|
| 68 | + $sDefaultModel = $sNamespaceBaseName.'\Model\\'.$sClassName; |
|
| 69 | + $sDefaultView = str_replace('\\', DIRECTORY_SEPARATOR, str_replace('Venus\\', '\\', $sNamespaceBaseName)).DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$sClassName.'.tpl'; |
|
| 70 | + $sDefaultLayout = str_replace('\\', DIRECTORY_SEPARATOR, str_replace('Venus\\', '\\', $sNamespaceBaseName)).DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.'Layout.tpl'; |
|
| 71 | + |
|
| 72 | + $this->model = function() use ($sDefaultModel) { return new $sDefaultModel; }; |
|
| 73 | + |
|
| 74 | + $this->view = function() use ($sDefaultView) { return Vendor::getVendor('Apollina\Template', $sDefaultView); }; |
|
| 75 | + |
|
| 76 | + $this->layout = function() use ($sDefaultLayout) { return Vendor::getVendor('Apollina\Template', $sDefaultLayout, true); }; |
|
| 77 | + |
|
| 78 | + $this->layout->assign('model', $sDefaultView); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $this->form = function() { return new Form(); }; |
|
| 82 | + $this->security = function() { return new Security(); }; |
|
| 83 | + $this->router = function() { return new Router; }; |
|
| 84 | + $this->mail = function() { return new Mail; }; |
|
| 85 | + $this->session = function() { return new Session; }; |
|
| 86 | + $this->translator = function() { return new I18n; }; |
|
| 87 | + $this->url = function() { return new UrlManager; }; |
|
| 88 | + $this->cookie = function() { return new Cookie; }; |
|
| 89 | + $this->di = function() { return new Di; }; |
|
| 90 | + $this->request = function() { return new Request; }; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Trigger on a model to initialize it. You could fill entity with it. |
|
| 94 | + */ |
|
| 95 | + if (method_exists(get_called_class(), 'initialize')) { |
|
| 96 | + |
|
| 97 | + if (!isset(self::$_aInitialize[get_called_class()])) { |
|
| 98 | + |
|
| 99 | + static::initialize(); |
|
| 100 | + self::$_aInitialize[get_called_class()] = true; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Trigger on a model to initialize it every time you construct it |
|
| 106 | + */ |
|
| 107 | + if (method_exists(get_called_class(), 'onConstruct')) { static::onConstruct(); } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * redirection HTTP |
|
| 112 | + * |
|
| 113 | + * @access public |
|
| 114 | + * @param string $sUrl url for the redirection |
|
| 115 | + * @param int $iHttpCode code of the http request |
|
| 116 | + * @return void |
|
| 117 | + */ |
|
| 118 | + public function redirect(string $sUrl, int $iHttpCode = 301) |
|
| 119 | + { |
|
| 120 | + if ($iHttpCode === 301) { header('Status: 301 Moved Permanently', false, 301); } |
|
| 121 | + else if ($iHttpCode === 302) { header('Status: Moved Temporarily', false, 301); } |
|
| 122 | + |
|
| 123 | + header('Location: '.$sUrl); |
|
| 124 | + exit; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * call an other action as you call action with URL/Cli |
|
| 129 | + * |
|
| 130 | + * @access public |
|
| 131 | + * @param string $sUri uri for the redirection |
|
| 132 | + * @param array $aParams parameters |
|
| 133 | + * @return void |
|
| 134 | + */ |
|
| 135 | + public function forward(string $sUri, array $aParams = array()) |
|
| 136 | + { |
|
| 137 | + $this->router->runByFoward($sUri, $aParams); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * call the 404 Not Found page |
|
| 142 | + * |
|
| 143 | + * @access public |
|
| 144 | + * @return void |
|
| 145 | + */ |
|
| 146 | + public function notFound() |
|
| 147 | + { |
|
| 148 | + $$this->router->runHttpErrorPage(404); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * call the 403 Forbidden page |
|
| 153 | + * |
|
| 154 | + * @access public |
|
| 155 | + * @return void |
|
| 156 | + */ |
|
| 157 | + public function forbidden() |
|
| 158 | + { |
|
| 159 | + $$this->router->runHttpErrorPage(403); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * get a property |
|
| 164 | + * |
|
| 165 | + * @access public |
|
| 166 | + * @param unknown_type $mKey |
|
| 167 | + * @return void |
|
| 168 | + */ |
|
| 169 | + public function __get($mKey) |
|
| 170 | + { |
|
| 171 | + if (isset($this->di) && property_exists($this, 'di')) { |
|
| 172 | + |
|
| 173 | + $mDi = $this->di->get($mKey); |
|
| 174 | + |
|
| 175 | + if (isset($mDi) && $mDi !== false) { return $mDi; } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return parent::__get($mKey); |
|
| 179 | + } |
|
| 180 | 180 | } |
@@ -103,8 +103,7 @@ discard block |
||
| 103 | 103 | if (!$this->_checkAccess()) { return false; } |
| 104 | 104 | if (!$this->_checkBlackListIps()) { return false; } |
| 105 | 105 | } |
| 106 | - } |
|
| 107 | - else if (isset($oSecurity->authentification) && $oSecurity->authentification === 'http_basic_validate_by_controller') { |
|
| 106 | + } else if (isset($oSecurity->authentification) && $oSecurity->authentification === 'http_basic_validate_by_controller') { |
|
| 108 | 107 | |
| 109 | 108 | if (!isset($_SERVER['PHP_AUTH_USER'])) { |
| 110 | 109 | |
@@ -217,9 +216,7 @@ discard block |
||
| 217 | 216 | $sLogin = self::$_sLogin; |
| 218 | 217 | $sPassword = Config::get('Security')->users->$sLogin->password; |
| 219 | 218 | |
| 220 | - if ($sPassword == self::$_sPassword) { return true; } |
|
| 221 | - else if ($sPassword == md5(self::$_sPassword)) { return true; } |
|
| 222 | - else { return false; } |
|
| 219 | + if ($sPassword == self::$_sPassword) { return true; } else if ($sPassword == md5(self::$_sPassword)) { return true; } else { return false; } |
|
| 223 | 220 | } |
| 224 | 221 | |
| 225 | 222 | /** |
@@ -32,17 +32,17 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class Yaml implements ResponseInterface |
| 34 | 34 | { |
| 35 | - /** |
|
| 36 | - * translate the content |
|
| 37 | - * @see \Venus\lib\Response\ResponseInterface::translate() |
|
| 38 | - * |
|
| 39 | - * @access public |
|
| 40 | - * @param mixed $mContent content to translate |
|
| 41 | - * @return mixed |
|
| 42 | - */ |
|
| 43 | - public static function translate($mContent) |
|
| 44 | - { |
|
| 45 | - return yaml_emit($mContent); |
|
| 46 | - } |
|
| 35 | + /** |
|
| 36 | + * translate the content |
|
| 37 | + * @see \Venus\lib\Response\ResponseInterface::translate() |
|
| 38 | + * |
|
| 39 | + * @access public |
|
| 40 | + * @param mixed $mContent content to translate |
|
| 41 | + * @return mixed |
|
| 42 | + */ |
|
| 43 | + public static function translate($mContent) |
|
| 44 | + { |
|
| 45 | + return yaml_emit($mContent); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | } |
@@ -33,17 +33,17 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class Json implements ResponseInterface |
| 35 | 35 | { |
| 36 | - /** |
|
| 37 | - * translate the content |
|
| 38 | - * @see \Venus\lib\Response\ResponseInterface::translate() |
|
| 39 | - * |
|
| 40 | - * @access public |
|
| 41 | - * @param mixed $mContent content to translate |
|
| 42 | - * @return mixed |
|
| 43 | - */ |
|
| 44 | - public static function translate($mContent) |
|
| 45 | - { |
|
| 46 | - return json_encode(ObjectOperation::objectToArray($mContent)); |
|
| 47 | - } |
|
| 36 | + /** |
|
| 37 | + * translate the content |
|
| 38 | + * @see \Venus\lib\Response\ResponseInterface::translate() |
|
| 39 | + * |
|
| 40 | + * @access public |
|
| 41 | + * @param mixed $mContent content to translate |
|
| 42 | + * @return mixed |
|
| 43 | + */ |
|
| 44 | + public static function translate($mContent) |
|
| 45 | + { |
|
| 46 | + return json_encode(ObjectOperation::objectToArray($mContent)); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | } |
@@ -32,17 +32,17 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class Mock implements ResponseInterface |
| 34 | 34 | { |
| 35 | - /** |
|
| 36 | - * translate the content |
|
| 37 | - * @see \Venus\lib\Response\ResponseInterface::translate() |
|
| 38 | - * |
|
| 39 | - * @access public |
|
| 40 | - * @param mixed $mContent content to translate |
|
| 41 | - * @return mixed |
|
| 42 | - */ |
|
| 43 | - public static function translate($mContent) |
|
| 44 | - { |
|
| 45 | - return $mContent; |
|
| 46 | - } |
|
| 35 | + /** |
|
| 36 | + * translate the content |
|
| 37 | + * @see \Venus\lib\Response\ResponseInterface::translate() |
|
| 38 | + * |
|
| 39 | + * @access public |
|
| 40 | + * @param mixed $mContent content to translate |
|
| 41 | + * @return mixed |
|
| 42 | + */ |
|
| 43 | + public static function translate($mContent) |
|
| 44 | + { |
|
| 45 | + return $mContent; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | } |
@@ -9,18 +9,18 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Request implements RequestInterface |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * get parameter |
|
| 14 | - * @param string $name |
|
| 15 | - * @param string $default |
|
| 16 | - * @return string |
|
| 17 | - */ |
|
| 18 | - public function get(string $name, string $default = null) : string |
|
| 19 | - { |
|
| 20 | - if (isset($_POST[$name]) && $_POST[$name] != '') { |
|
| 21 | - return $_POST[$name]; |
|
| 22 | - } else if ($default !== null) { |
|
| 23 | - return $default; |
|
| 24 | - } |
|
| 25 | - } |
|
| 12 | + /** |
|
| 13 | + * get parameter |
|
| 14 | + * @param string $name |
|
| 15 | + * @param string $default |
|
| 16 | + * @return string |
|
| 17 | + */ |
|
| 18 | + public function get(string $name, string $default = null) : string |
|
| 19 | + { |
|
| 20 | + if (isset($_POST[$name]) && $_POST[$name] != '') { |
|
| 21 | + return $_POST[$name]; |
|
| 22 | + } else if ($default !== null) { |
|
| 23 | + return $default; |
|
| 24 | + } |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -9,18 +9,18 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Query implements RequestInterface |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * get parameter |
|
| 14 | - * @param string $name |
|
| 15 | - * @param string $default |
|
| 16 | - * @return string |
|
| 17 | - */ |
|
| 18 | - public function get(string $name, string $default = null) : string |
|
| 19 | - { |
|
| 20 | - if (isset($_GET[$name]) && $_GET[$name] != '') { |
|
| 21 | - return $_GET[$name]; |
|
| 22 | - } else if ($default !== null) { |
|
| 23 | - return $default; |
|
| 24 | - } |
|
| 25 | - } |
|
| 12 | + /** |
|
| 13 | + * get parameter |
|
| 14 | + * @param string $name |
|
| 15 | + * @param string $default |
|
| 16 | + * @return string |
|
| 17 | + */ |
|
| 18 | + public function get(string $name, string $default = null) : string |
|
| 19 | + { |
|
| 20 | + if (isset($_GET[$name]) && $_GET[$name] != '') { |
|
| 21 | + return $_GET[$name]; |
|
| 22 | + } else if ($default !== null) { |
|
| 23 | + return $default; |
|
| 24 | + } |
|
| 25 | + } |
|
| 26 | 26 | } |