增加接口类 规范驱动扩展

This commit is contained in:
thinkphp
2016-05-05 07:39:05 +08:00
parent 3774e3451a
commit 7a8bb3b54f
33 changed files with 237 additions and 64 deletions

View File

@@ -18,7 +18,7 @@ use think\Exception;
* Apc缓存驱动 * Apc缓存驱动
* @author liu21st <liu21st@gmail.com> * @author liu21st <liu21st@gmail.com>
*/ */
class Apc class Apc implements CacheInterface
{ {
protected $options = [ protected $options = [

View File

@@ -0,0 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
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();
}

View File

@@ -24,7 +24,7 @@ use think\Cache;
* ); * );
* @author liu21st <liu21st@gmail.com> * @author liu21st <liu21st@gmail.com>
*/ */
class Db class Db implements CacheInterface
{ {
protected $handler = null; protected $handler = null;

View File

@@ -17,7 +17,7 @@ use think\Cache;
* 文件类型缓存类 * 文件类型缓存类
* @author liu21st <liu21st@gmail.com> * @author liu21st <liu21st@gmail.com>
*/ */
class File class File implements CacheInterface
{ {
protected $options = [ protected $options = [

View File

@@ -17,7 +17,7 @@ use think\Cache;
* 文件类型缓存类 * 文件类型缓存类
* @author liu21st <liu21st@gmail.com> * @author liu21st <liu21st@gmail.com>
*/ */
class Lite class Lite implements CacheInterface
{ {
protected $options = [ protected $options = [
'prefix' => '', 'prefix' => '',

View File

@@ -14,7 +14,7 @@ namespace think\cache\driver;
use think\Cache; use think\Cache;
use think\Exception; use think\Exception;
class Memcache class Memcache implements CacheInterface
{ {
protected $handler = null; protected $handler = null;
protected $options = [ protected $options = [

View File

@@ -14,7 +14,7 @@ namespace think\cache\driver;
use think\Cache; use think\Cache;
use think\Exception; use think\Exception;
class Memcached class Memcached implements CacheInterface
{ {
protected $handler = null; protected $handler = null;
protected $options = [ protected $options = [

View File

@@ -19,7 +19,7 @@ use think\Exception;
* 要求安装phpredis扩展https://github.com/nicolasff/phpredis * 要求安装phpredis扩展https://github.com/nicolasff/phpredis
* @author 尘缘 <130775@qq.com> * @author 尘缘 <130775@qq.com>
*/ */
class Redis class Redis implements CacheInterface
{ {
protected $handler = null; protected $handler = null;
protected $options = [ protected $options = [
@@ -68,7 +68,7 @@ class Redis
$value = $this->handler->get($this->options['prefix'] . $name); $value = $this->handler->get($this->options['prefix'] . $name);
$jsonData = json_decode($value, true); $jsonData = json_decode($value, true);
// 检测是否为JSON数据 true 返回JSON解析数组, false返回源数据 byron sampson<xiaobo.sun@qq.com> // 检测是否为JSON数据 true 返回JSON解析数组, false返回源数据 byron sampson<xiaobo.sun@qq.com>
return ($jsonData === null) ? $value : $jsonData; return (null === $jsonData) ? $value : $jsonData;
} }
/** /**

View File

@@ -18,7 +18,7 @@ use think\Exception;
* SAE Memcache缓存驱动 * SAE Memcache缓存驱动
* @author liu21st <liu21st@gmail.com> * @author liu21st <liu21st@gmail.com>
*/ */
class Sae class Sae implements CacheInterface
{ {
protected $handler = null; protected $handler = null;
protected $options = [ protected $options = [

View File

@@ -17,7 +17,7 @@ use think\Cache;
* Secache缓存驱动 * Secache缓存驱动
* @author liu21st <liu21st@gmail.com> * @author liu21st <liu21st@gmail.com>
*/ */
class Secache class Secache implements CacheInterface
{ {
protected $handler = null; protected $handler = null;

View File

@@ -18,7 +18,7 @@ use think\Exception;
* Sqlite缓存驱动 * Sqlite缓存驱动
* @author liu21st <liu21st@gmail.com> * @author liu21st <liu21st@gmail.com>
*/ */
class Sqlite class Sqlite implements CacheInterface
{ {
protected $options = [ protected $options = [

View File

@@ -17,7 +17,7 @@ use think\Cache;
* 测试缓存类 * 测试缓存类
* @author liu21st <liu21st@gmail.com> * @author liu21st <liu21st@gmail.com>
*/ */
class Test class Test implements CacheInterface
{ {
/** /**

View File

@@ -18,7 +18,7 @@ use think\Exception;
* Wincache缓存驱动 * Wincache缓存驱动
* @author liu21st <liu21st@gmail.com> * @author liu21st <liu21st@gmail.com>
*/ */
class Wincache class Wincache implements CacheInterface
{ {
protected $options = [ protected $options = [

View File

@@ -18,7 +18,7 @@ use think\Exception;
* Xcache缓存驱动 * Xcache缓存驱动
* @author liu21st <liu21st@gmail.com> * @author liu21st <liu21st@gmail.com>
*/ */
class Xcache class Xcache implements CacheInterface
{ {
protected $options = [ protected $options = [

View File

@@ -0,0 +1,25 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\config\driver;
interface ConfigInterface
{
/**
* 解析配置
* @access public
* @param mixed $config 配置
* @return mixed
*/
public function parse($config);
}

View File

@@ -11,7 +11,7 @@
namespace think\config\driver; namespace think\config\driver;
class Ini class Ini implements ConfigInterface
{ {
public function parse($config) public function parse($config)
{ {

View File

@@ -11,7 +11,7 @@
namespace think\config\driver; namespace think\config\driver;
class Xml class Xml implements ConfigInterface
{ {
public function parse($config) public function parse($config)
{ {

View File

@@ -21,7 +21,7 @@ use think\exception\DbBindParamException;
use think\exception\PDOException; use think\exception\PDOException;
use think\Log; use think\Log;
abstract class Connection abstract class Connection implements ConnectionInterface
{ {
// PDO操作实例 // PDO操作实例
protected $PDOStatement; 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 * @access public

View File

@@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
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);
}

View File

@@ -26,7 +26,7 @@ class Mysql extends Connection
* @param array $config 连接信息 * @param array $config 连接信息
* @return string * @return string
*/ */
protected function parseDsn($config) public function parseDsn($config)
{ {
$dsn = 'mysql:dbname=' . $config['database'] . ';host=' . $config['hostname']; $dsn = 'mysql:dbname=' . $config['database'] . ';host=' . $config['hostname'];
if (!empty($config['hostport'])) { if (!empty($config['hostport'])) {
@@ -91,11 +91,11 @@ class Mysql extends Connection
/** /**
* SQL性能分析 * SQL性能分析
* @access protected * @access public
* @param string $sql * @param string $sql
* @return array * @return array
*/ */
protected function getExplain($sql) public function getExplain($sql)
{ {
$pdo = $this->linkID->query("EXPLAIN " . $sql); $pdo = $this->linkID->query("EXPLAIN " . $sql);
$result = $pdo->fetch(\PDO::FETCH_ASSOC); $result = $pdo->fetch(\PDO::FETCH_ASSOC);

View File

@@ -28,7 +28,7 @@ class Oracle extends Connection
* @param array $config 连接信息 * @param array $config 连接信息
* @return string * @return string
*/ */
protected function parseDsn($config) public function parseDsn($config)
{ {
$dsn = 'oci:dbname='; $dsn = 'oci:dbname=';
if (!empty($config['hostname'])) { if (!empty($config['hostname'])) {
@@ -139,11 +139,11 @@ class Oracle extends Connection
/** /**
* SQL性能分析 * SQL性能分析
* @access protected * @access public
* @param string $sql * @param string $sql
* @return array * @return array
*/ */
protected function getExplain($sql) public function getExplain($sql)
{ {
return []; return [];
} }

View File

@@ -25,7 +25,7 @@ class Pgsql extends Connection
* @param array $config 连接信息 * @param array $config 连接信息
* @return string * @return string
*/ */
protected function parseDsn($config) public function parseDsn($config)
{ {
$dsn = 'pgsql:dbname=' . $config['database'] . ';host=' . $config['hostname']; $dsn = 'pgsql:dbname=' . $config['database'] . ';host=' . $config['hostname'];
if (!empty($config['hostport'])) { if (!empty($config['hostport'])) {
@@ -79,11 +79,11 @@ class Pgsql extends Connection
/** /**
* SQL性能分析 * SQL性能分析
* @access protected * @access public
* @param string $sql * @param string $sql
* @return array * @return array
*/ */
protected function getExplain($sql) public function getExplain($sql)
{ {
return []; return [];
} }

View File

@@ -25,7 +25,7 @@ class Sqlite extends Connection
* @param array $config 连接信息 * @param array $config 连接信息
* @return string * @return string
*/ */
protected function parseDsn($config) public function parseDsn($config)
{ {
$dsn = 'sqlite:' . $config['database']; $dsn = 'sqlite:' . $config['database'];
return $dsn; return $dsn;
@@ -78,11 +78,11 @@ class Sqlite extends Connection
/** /**
* SQL性能分析 * SQL性能分析
* @access protected * @access public
* @param string $sql * @param string $sql
* @return array * @return array
*/ */
protected function getExplain($sql) public function getExplain($sql)
{ {
return []; return [];
} }

View File

@@ -33,7 +33,7 @@ class Sqlsrv extends Connection
* @param array $config 连接信息 * @param array $config 连接信息
* @return string * @return string
*/ */
protected function parseDsn($config) public function parseDsn($config)
{ {
$dsn = 'sqlsrv:Database=' . $config['database'] . ';Server=' . $config['hostname']; $dsn = 'sqlsrv:Database=' . $config['database'] . ';Server=' . $config['hostname'];
if (!empty($config['hostport'])) { if (!empty($config['hostport'])) {
@@ -96,11 +96,11 @@ class Sqlsrv extends Connection
/** /**
* SQL性能分析 * SQL性能分析
* @access protected * @access public
* @param string $sql * @param string $sql
* @return array * @return array
*/ */
protected function getExplain($sql) public function getExplain($sql)
{ {
return []; return [];
} }

View File

@@ -13,7 +13,7 @@ namespace think\log\driver;
/** /**
* 本地化调试输出到文件 * 本地化调试输出到文件
*/ */
class File class File implements LogInterface
{ {
protected $config = [ protected $config = [
'time_format' => ' c ', 'time_format' => ' c ',

View File

@@ -0,0 +1,25 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\log\driver;
interface LogInterface
{
/**
* 日志写入接口
* @access public
* @param array $log 日志信息
* @return bool
*/
public function save(array $log = []);
}

View File

@@ -13,7 +13,7 @@ namespace think\log\driver;
/** /**
* 调试输出到SAE * 调试输出到SAE
*/ */
class Sae class Sae implements LogInterface
{ {
protected $config = [ protected $config = [
'log_time_format' => ' c ', 'log_time_format' => ' c ',

View File

@@ -5,7 +5,7 @@
*/ */
namespace think\log\driver; namespace think\log\driver;
class Socket class Socket implements LogInterface
{ {
public $port = 1116; //SocketLog 服务的http的端口号 public $port = 1116; //SocketLog 服务的http的端口号

View File

@@ -13,7 +13,7 @@ namespace think\log\driver;
/** /**
* 模拟测试输出 * 模拟测试输出
*/ */
class Test class Test implements LogInterface
{ {
/** /**
* 日志写入接口 * 日志写入接口

View File

@@ -16,7 +16,7 @@ use think\Debug;
/** /**
* 页面Trace调试 * 页面Trace调试
*/ */
class Trace class Trace implements LogInterface
{ {
protected $config = [ protected $config = [
'trace_file' => '', 'trace_file' => '',

View File

@@ -13,7 +13,7 @@ namespace think\view\driver;
use think\Exception; use think\Exception;
use think\Log; use think\Log;
class Php class Php implements ViewInterface
{ {
// 模板引擎参数 // 模板引擎参数
protected $config = [ protected $config = [

View File

@@ -14,7 +14,7 @@ use think\Exception;
use think\Log; use think\Log;
use think\Template; use think\Template;
class Think class Think implements ViewInterface
{ {
// 模板引擎实例 // 模板引擎实例
private $template = null; private $template = null;

View File

@@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
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 = []);
}