diff --git a/library/think/cache/driver/Apc.php b/library/think/cache/driver/Apc.php index 9087c11c..05ee8a29 100644 --- a/library/think/cache/driver/Apc.php +++ b/library/think/cache/driver/Apc.php @@ -18,7 +18,7 @@ use think\Exception; * Apc缓存驱动 * @author liu21st */ -class Apc +class Apc implements CacheInterface { protected $options = [ diff --git a/library/think/cache/driver/CacheInterface.php b/library/think/cache/driver/CacheInterface.php new file mode 100644 index 00000000..93716c76 --- /dev/null +++ b/library/think/cache/driver/CacheInterface.php @@ -0,0 +1,50 @@ + +// +---------------------------------------------------------------------- + +namespace think\cache\driver; + +interface CacheInterface +{ + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name); + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param int $expire 有效时间 0为永久 + * @return boolean + */ + public function set($name, $value, $expire = null); + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name); + + /** + * 清除缓存 + * @access public + * @return boolean + */ + public function clear(); + +} diff --git a/library/think/cache/driver/Db.php b/library/think/cache/driver/Db.php index d1d71b58..e8bc9283 100644 --- a/library/think/cache/driver/Db.php +++ b/library/think/cache/driver/Db.php @@ -24,23 +24,23 @@ use think\Cache; * ); * @author liu21st */ -class Db +class Db implements CacheInterface { protected $handler = null; protected $options = [ - 'type' => '', - 'dsn' => '', - 'hostname' => '', - 'hostport' => '', - 'username' => '', - 'password' => '', - 'database' => '', - 'charset' => '', - 'table' => '', - 'prefix' => '', - 'expire' => 0, - 'length' => 0, + 'type' => '', + 'dsn' => '', + 'hostname' => '', + 'hostport' => '', + 'username' => '', + 'password' => '', + 'database' => '', + 'charset' => '', + 'table' => '', + 'prefix' => '', + 'expire' => 0, + 'length' => 0, ]; /** @@ -162,4 +162,4 @@ class Db return $this->handler->execute('TRUNCATE TABLE `' . $this->options['table'] . '`'); } -} \ No newline at end of file +} diff --git a/library/think/cache/driver/File.php b/library/think/cache/driver/File.php index bf2fd1d7..48fd2327 100644 --- a/library/think/cache/driver/File.php +++ b/library/think/cache/driver/File.php @@ -17,7 +17,7 @@ use think\Cache; * 文件类型缓存类 * @author liu21st */ -class File +class File implements CacheInterface { protected $options = [ @@ -186,7 +186,7 @@ class File */ public function clear() { - $fileLsit = (array)glob($this->options['path'].'*'); + $fileLsit = (array) glob($this->options['path'] . '*'); foreach ($fileLsit as $path) { is_file($path) && unlink($path); } diff --git a/library/think/cache/driver/Lite.php b/library/think/cache/driver/Lite.php index 3dc5e4f5..2967b586 100644 --- a/library/think/cache/driver/Lite.php +++ b/library/think/cache/driver/Lite.php @@ -17,7 +17,7 @@ use think\Cache; * 文件类型缓存类 * @author liu21st */ -class Lite +class Lite implements CacheInterface { protected $options = [ 'prefix' => '', diff --git a/library/think/cache/driver/Memcache.php b/library/think/cache/driver/Memcache.php index c4c63b21..0fb11cff 100644 --- a/library/think/cache/driver/Memcache.php +++ b/library/think/cache/driver/Memcache.php @@ -14,7 +14,7 @@ namespace think\cache\driver; use think\Cache; use think\Exception; -class Memcache +class Memcache implements CacheInterface { protected $handler = null; protected $options = [ diff --git a/library/think/cache/driver/Memcached.php b/library/think/cache/driver/Memcached.php index 7521e758..16631a39 100644 --- a/library/think/cache/driver/Memcached.php +++ b/library/think/cache/driver/Memcached.php @@ -14,7 +14,7 @@ namespace think\cache\driver; use think\Cache; use think\Exception; -class Memcached +class Memcached implements CacheInterface { protected $handler = null; protected $options = [ diff --git a/library/think/cache/driver/Redis.php b/library/think/cache/driver/Redis.php index 8dbce0e5..999122c6 100644 --- a/library/think/cache/driver/Redis.php +++ b/library/think/cache/driver/Redis.php @@ -19,7 +19,7 @@ use think\Exception; * 要求安装phpredis扩展:https://github.com/nicolasff/phpredis * @author 尘缘 <130775@qq.com> */ -class Redis +class Redis implements CacheInterface { protected $handler = null; protected $options = [ @@ -65,10 +65,10 @@ class Redis public function get($name) { Cache::$readTimes++; - $value = $this->handler->get($this->options['prefix'] . $name); - $jsonData = json_decode( $value, true ); + $value = $this->handler->get($this->options['prefix'] . $name); + $jsonData = json_decode($value, true); // 检测是否为JSON数据 true 返回JSON解析数组, false返回源数据 byron sampson - return ($jsonData === null) ? $value : $jsonData; + return (null === $jsonData) ? $value : $jsonData; } /** @@ -87,7 +87,7 @@ class Redis } $name = $this->options['prefix'] . $name; //对数组/对象数据进行缓存处理,保证数据完整性 byron sampson - $value = (is_object($value) || is_array($value)) ? json_encode($value) : $value; + $value = (is_object($value) || is_array($value)) ? json_encode($value) : $value; if (is_int($expire)) { $result = $this->handler->setex($name, $expire, $value); } else { diff --git a/library/think/cache/driver/Sae.php b/library/think/cache/driver/Sae.php index 6d861f0e..cb817b28 100644 --- a/library/think/cache/driver/Sae.php +++ b/library/think/cache/driver/Sae.php @@ -18,7 +18,7 @@ use think\Exception; * SAE Memcache缓存驱动 * @author liu21st */ -class Sae +class Sae implements CacheInterface { protected $handler = null; protected $options = [ diff --git a/library/think/cache/driver/Secache.php b/library/think/cache/driver/Secache.php index 074c3362..950641be 100644 --- a/library/think/cache/driver/Secache.php +++ b/library/think/cache/driver/Secache.php @@ -17,7 +17,7 @@ use think\Cache; * Secache缓存驱动 * @author liu21st */ -class Secache +class Secache implements CacheInterface { protected $handler = null; diff --git a/library/think/cache/driver/Sqlite.php b/library/think/cache/driver/Sqlite.php index e2c63d4d..57132722 100644 --- a/library/think/cache/driver/Sqlite.php +++ b/library/think/cache/driver/Sqlite.php @@ -18,7 +18,7 @@ use think\Exception; * Sqlite缓存驱动 * @author liu21st */ -class Sqlite +class Sqlite implements CacheInterface { protected $options = [ diff --git a/library/think/cache/driver/Test.php b/library/think/cache/driver/Test.php index 95ea31e1..ee26da00 100644 --- a/library/think/cache/driver/Test.php +++ b/library/think/cache/driver/Test.php @@ -17,7 +17,7 @@ use think\Cache; * 测试缓存类 * @author liu21st */ -class Test +class Test implements CacheInterface { /** diff --git a/library/think/cache/driver/Wincache.php b/library/think/cache/driver/Wincache.php index 491c6c29..18858a19 100644 --- a/library/think/cache/driver/Wincache.php +++ b/library/think/cache/driver/Wincache.php @@ -18,7 +18,7 @@ use think\Exception; * Wincache缓存驱动 * @author liu21st */ -class Wincache +class Wincache implements CacheInterface { protected $options = [ diff --git a/library/think/cache/driver/Xcache.php b/library/think/cache/driver/Xcache.php index 5cca03ac..b128fe3c 100644 --- a/library/think/cache/driver/Xcache.php +++ b/library/think/cache/driver/Xcache.php @@ -18,7 +18,7 @@ use think\Exception; * Xcache缓存驱动 * @author liu21st */ -class Xcache +class Xcache implements CacheInterface { protected $options = [ diff --git a/library/think/config/driver/ConfigInterface.php b/library/think/config/driver/ConfigInterface.php new file mode 100644 index 00000000..c38727c9 --- /dev/null +++ b/library/think/config/driver/ConfigInterface.php @@ -0,0 +1,25 @@ + +// +---------------------------------------------------------------------- + +namespace think\config\driver; + +interface ConfigInterface +{ + + /** + * 解析配置 + * @access public + * @param mixed $config 配置 + * @return mixed + */ + public function parse($config); + +} diff --git a/library/think/config/driver/Ini.php b/library/think/config/driver/Ini.php index d8dc558d..61a49df6 100644 --- a/library/think/config/driver/Ini.php +++ b/library/think/config/driver/Ini.php @@ -11,7 +11,7 @@ namespace think\config\driver; -class Ini +class Ini implements ConfigInterface { public function parse($config) { diff --git a/library/think/config/driver/Xml.php b/library/think/config/driver/Xml.php index 5bc93015..6cbd82bc 100644 --- a/library/think/config/driver/Xml.php +++ b/library/think/config/driver/Xml.php @@ -11,7 +11,7 @@ namespace think\config\driver; -class Xml +class Xml implements ConfigInterface { public function parse($config) { diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index 794198a2..e225e2bc 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -21,7 +21,7 @@ use think\exception\DbBindParamException; use think\exception\PDOException; use think\Log; -abstract class Connection +abstract class Connection implements ConnectionInterface { // PDO操作实例 protected $PDOStatement; @@ -226,14 +226,6 @@ abstract class Connection } } - /** - * 解析pdo连接的dsn信息(由驱动扩展) - * @access public - * @param array $config 连接信息 - * @return string - */ - abstract protected function parseDsn($config); - /** * 释放查询结果 * @access public diff --git a/library/think/db/ConnectionInterface.php b/library/think/db/ConnectionInterface.php new file mode 100644 index 00000000..f7930fe4 --- /dev/null +++ b/library/think/db/ConnectionInterface.php @@ -0,0 +1,47 @@ + +// +---------------------------------------------------------------------- + +namespace think\db; + +interface ConnectionInterface +{ + /** + * 解析pdo连接的dsn信息 + * @access public + * @param array $config 连接信息 + * @return string + */ + public function parseDsn($config); + + /** + * 取得数据表的字段信息 + * @access public + * @param string $tableName + * @return array + */ + public function getFields($tableName); + + /** + * 取得数据库的表信息 + * @access public + * @param string $dbName + * @return array + */ + public function getTables($dbName); + + /** + * SQL性能分析 + * @access protected + * @param string $sql + * @return array + */ + public function getExplain($sql); +} diff --git a/library/think/db/connector/Mysql.php b/library/think/db/connector/Mysql.php index 32c75ce9..31f469d0 100644 --- a/library/think/db/connector/Mysql.php +++ b/library/think/db/connector/Mysql.php @@ -26,7 +26,7 @@ class Mysql extends Connection * @param array $config 连接信息 * @return string */ - protected function parseDsn($config) + public function parseDsn($config) { $dsn = 'mysql:dbname=' . $config['database'] . ';host=' . $config['hostname']; if (!empty($config['hostport'])) { @@ -91,11 +91,11 @@ class Mysql extends Connection /** * SQL性能分析 - * @access protected + * @access public * @param string $sql * @return array */ - protected function getExplain($sql) + public function getExplain($sql) { $pdo = $this->linkID->query("EXPLAIN " . $sql); $result = $pdo->fetch(\PDO::FETCH_ASSOC); diff --git a/library/think/db/connector/Oracle.php b/library/think/db/connector/Oracle.php index 055aa604..f0398307 100644 --- a/library/think/db/connector/Oracle.php +++ b/library/think/db/connector/Oracle.php @@ -28,7 +28,7 @@ class Oracle extends Connection * @param array $config 连接信息 * @return string */ - protected function parseDsn($config) + public function parseDsn($config) { $dsn = 'oci:dbname='; if (!empty($config['hostname'])) { @@ -139,11 +139,11 @@ class Oracle extends Connection /** * SQL性能分析 - * @access protected + * @access public * @param string $sql * @return array */ - protected function getExplain($sql) + public function getExplain($sql) { return []; } diff --git a/library/think/db/connector/Pgsql.php b/library/think/db/connector/Pgsql.php index 95c02a0b..d58ddbc1 100644 --- a/library/think/db/connector/Pgsql.php +++ b/library/think/db/connector/Pgsql.php @@ -25,7 +25,7 @@ class Pgsql extends Connection * @param array $config 连接信息 * @return string */ - protected function parseDsn($config) + public function parseDsn($config) { $dsn = 'pgsql:dbname=' . $config['database'] . ';host=' . $config['hostname']; if (!empty($config['hostport'])) { @@ -79,11 +79,11 @@ class Pgsql extends Connection /** * SQL性能分析 - * @access protected + * @access public * @param string $sql * @return array */ - protected function getExplain($sql) + public function getExplain($sql) { return []; } diff --git a/library/think/db/connector/Sqlite.php b/library/think/db/connector/Sqlite.php index 7e85bd7b..4984be0d 100644 --- a/library/think/db/connector/Sqlite.php +++ b/library/think/db/connector/Sqlite.php @@ -25,7 +25,7 @@ class Sqlite extends Connection * @param array $config 连接信息 * @return string */ - protected function parseDsn($config) + public function parseDsn($config) { $dsn = 'sqlite:' . $config['database']; return $dsn; @@ -78,11 +78,11 @@ class Sqlite extends Connection /** * SQL性能分析 - * @access protected + * @access public * @param string $sql * @return array */ - protected function getExplain($sql) + public function getExplain($sql) { return []; } diff --git a/library/think/db/connector/Sqlsrv.php b/library/think/db/connector/Sqlsrv.php index fe5ae149..4044181c 100644 --- a/library/think/db/connector/Sqlsrv.php +++ b/library/think/db/connector/Sqlsrv.php @@ -33,7 +33,7 @@ class Sqlsrv extends Connection * @param array $config 连接信息 * @return string */ - protected function parseDsn($config) + public function parseDsn($config) { $dsn = 'sqlsrv:Database=' . $config['database'] . ';Server=' . $config['hostname']; if (!empty($config['hostport'])) { @@ -96,11 +96,11 @@ class Sqlsrv extends Connection /** * SQL性能分析 - * @access protected + * @access public * @param string $sql * @return array */ - protected function getExplain($sql) + public function getExplain($sql) { return []; } diff --git a/library/think/log/driver/File.php b/library/think/log/driver/File.php index b3fa9c42..6fa7ce5e 100644 --- a/library/think/log/driver/File.php +++ b/library/think/log/driver/File.php @@ -13,7 +13,7 @@ namespace think\log\driver; /** * 本地化调试输出到文件 */ -class File +class File implements LogInterface { protected $config = [ 'time_format' => ' c ', diff --git a/library/think/log/driver/LogInterface.php b/library/think/log/driver/LogInterface.php new file mode 100644 index 00000000..7f394f64 --- /dev/null +++ b/library/think/log/driver/LogInterface.php @@ -0,0 +1,25 @@ + +// +---------------------------------------------------------------------- + +namespace think\log\driver; + +interface LogInterface +{ + + /** + * 日志写入接口 + * @access public + * @param array $log 日志信息 + * @return bool + */ + public function save(array $log = []); + +} diff --git a/library/think/log/driver/Sae.php b/library/think/log/driver/Sae.php index 7f3c3349..3a8c37a0 100644 --- a/library/think/log/driver/Sae.php +++ b/library/think/log/driver/Sae.php @@ -13,7 +13,7 @@ namespace think\log\driver; /** * 调试输出到SAE */ -class Sae +class Sae implements LogInterface { protected $config = [ 'log_time_format' => ' c ', diff --git a/library/think/log/driver/Socket.php b/library/think/log/driver/Socket.php index 6a5e87f7..d3950a4d 100644 --- a/library/think/log/driver/Socket.php +++ b/library/think/log/driver/Socket.php @@ -5,7 +5,7 @@ */ namespace think\log\driver; -class Socket +class Socket implements LogInterface { public $port = 1116; //SocketLog 服务的http的端口号 diff --git a/library/think/log/driver/Test.php b/library/think/log/driver/Test.php index e367ca3c..fdd1b118 100644 --- a/library/think/log/driver/Test.php +++ b/library/think/log/driver/Test.php @@ -13,7 +13,7 @@ namespace think\log\driver; /** * 模拟测试输出 */ -class Test +class Test implements LogInterface { /** * 日志写入接口 diff --git a/library/think/log/driver/Trace.php b/library/think/log/driver/Trace.php index d40f1071..dc83acf8 100644 --- a/library/think/log/driver/Trace.php +++ b/library/think/log/driver/Trace.php @@ -16,7 +16,7 @@ use think\Debug; /** * 页面Trace调试 */ -class Trace +class Trace implements LogInterface { protected $config = [ 'trace_file' => '', diff --git a/library/think/view/driver/Php.php b/library/think/view/driver/Php.php index fab8d688..4fcbf2ac 100644 --- a/library/think/view/driver/Php.php +++ b/library/think/view/driver/Php.php @@ -13,7 +13,7 @@ namespace think\view\driver; use think\Exception; use think\Log; -class Php +class Php implements ViewInterface { // 模板引擎参数 protected $config = [ diff --git a/library/think/view/driver/Think.php b/library/think/view/driver/Think.php index f06406c8..e95d15b2 100644 --- a/library/think/view/driver/Think.php +++ b/library/think/view/driver/Think.php @@ -14,7 +14,7 @@ use think\Exception; use think\Log; use think\Template; -class Think +class Think implements ViewInterface { // 模板引擎实例 private $template = null; diff --git a/library/think/view/driver/ViewInterface.php b/library/think/view/driver/ViewInterface.php new file mode 100644 index 00000000..ffe1da71 --- /dev/null +++ b/library/think/view/driver/ViewInterface.php @@ -0,0 +1,34 @@ + +// +---------------------------------------------------------------------- + +namespace think\view\driver; + +interface ViewInterface +{ + /** + * 渲染模板文件 + * @access public + * @param string $template 模板文件 + * @param array $data 模板变量 + * @return void + */ + public function fetch($template, $data = []); + + /** + * 渲染模板内容 + * @access public + * @param string $content 模板内容 + * @param array $data 模板变量 + * @return void + */ + public function display($content, $data = []); + +}