注释和规范化调整及完善

注释和规范化调整及完善,以及部分代码优化
This commit is contained in:
yicheng
2015-12-06 01:56:10 +08:00
parent 491e33af8f
commit 47335634e9
37 changed files with 385 additions and 187 deletions

View File

@@ -62,7 +62,7 @@ function C($name = '', $value = null, $range = '')
if (is_null($value)) { if (is_null($value)) {
return think\Config::get($name, $range); return think\Config::get($name, $range);
} else { } else {
think\Config::set($name, $value, $range); return think\Config::set($name, $value, $range);
} }
} }
@@ -100,7 +100,7 @@ function G($start, $end = '', $dec = 6)
* @param string $name Model名称 支持指定基础模型 例如 MongoModel:User * @param string $name Model名称 支持指定基础模型 例如 MongoModel:User
* @param string $tablePrefix 表前缀 * @param string $tablePrefix 表前缀
* @param mixed $connection 数据库连接信息 * @param mixed $connection 数据库连接信息
* @return Model * @return \Think\Model
*/ */
function M($name = '', $tablePrefix = '', $connection = '') function M($name = '', $tablePrefix = '', $connection = '')
{ {
@@ -188,9 +188,11 @@ function T($class, $ext = EXT)
/** /**
* 抛出异常处理 * 抛出异常处理
*
* @param string $msg 异常消息 * @param string $msg 异常消息
* @param integer $code 异常代码 默认为0 * @param integer $code 异常代码 默认为0
* @return void *
* @throws \think\Exception
*/ */
function E($msg, $code = 0) function E($msg, $code = 0)
{ {
@@ -213,7 +215,7 @@ function dump($var, $echo = true, $label = null)
* 渲染输出Widget * 渲染输出Widget
* @param string $name Widget名称 * @param string $name Widget名称
* @param array $data 传人的参数 * @param array $data 传人的参数
* @return void * @return mixed
*/ */
function W($name, $data = []) function W($name, $data = [])
{ {
@@ -238,7 +240,7 @@ function session($name, $value = '')
return think\Session::get($name); return think\Session::get($name);
} elseif (is_null($value)) { } elseif (is_null($value)) {
// 删除session // 删除session
return think\Session::delete($name); think\Session::delete($name);
} else { } else {
// 设置session // 设置session
think\Session::set($name, $value); think\Session::set($name, $value);

View File

@@ -41,8 +41,8 @@ class ContentReplace
$script_name = rtrim($_SERVER['SCRIPT_NAME'],'/'); $script_name = rtrim($_SERVER['SCRIPT_NAME'],'/');
} }
define('ROOT_URL', rtrim(dirname(str_replace("\\","\/",$script_name)),'/')); define('ROOT_URL', rtrim(dirname(str_replace("\\","\/",$script_name)),'/'));
define('MODULE_URL', ROOT_URL.'/'.(defined('MODULE_ALIAS')?MODULE_ALIAS:MODULE_NAME); define('MODULE_URL', ROOT_URL.'/'.(defined('MODULE_ALIAS')?MODULE_ALIAS:MODULE_NAME));
define('CONTROLLER_URL', MODULE_URL.'/'.CONTROLLER_NAME; define('CONTROLLER_URL', MODULE_URL.'/'.CONTROLLER_NAME);
define('ACTION_URL', CONTROLLER_URL.'/'.ACTION_NAME); define('ACTION_URL', CONTROLLER_URL.'/'.ACTION_NAME);
// 系统默认的特殊变量替换 // 系统默认的特殊变量替换

View File

@@ -28,8 +28,11 @@ class LocationTemplate
/** /**
* 自动定位模板文件 * 自动定位模板文件
* @access private * @access private
* @param string $templateFile 文件名 *
* @param $template
*
* @return string * @return string
* @internal param string $templateFile 文件名
*/ */
private function parseTemplateFile($template) private function parseTemplateFile($template)
{ {
@@ -39,8 +42,6 @@ class LocationTemplate
$template = CONTROLLER_NAME . '/' . ACTION_NAME; $template = CONTROLLER_NAME . '/' . ACTION_NAME;
} elseif (false === strpos($template, '/')) { } elseif (false === strpos($template, '/')) {
$template = CONTROLLER_NAME . '/' . $template; $template = CONTROLLER_NAME . '/' . $template;
} elseif (false === strpos($template, '.')) {
$template = $template;
} }
$templateFile = MODULE_PATH . 'view/' . $template . '.html'; $templateFile = MODULE_PATH . 'view/' . $template . '.html';
return $templateFile; return $templateFile;

View File

@@ -104,7 +104,7 @@ class ReadHtmlCache
* @access public * @access public
* @param string $cacheFile 静态文件名 * @param string $cacheFile 静态文件名
* @param integer $cacheTime 缓存有效期 * @param integer $cacheTime 缓存有效期
* @return boolen * @return bool
*/ */
public static function checkHTMLCache($cacheFile = '', $cacheTime = '') public static function checkHTMLCache($cacheFile = '', $cacheTime = '')
{ {

View File

@@ -8,8 +8,8 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com> // | Author: liu21st <liu21st@gmail.com>
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace think\behavior; namespace think\behavior;
use think\Behavior;
/** /**
* 系统行为扩展:表单令牌生成 * 系统行为扩展:表单令牌生成

View File

@@ -16,9 +16,13 @@ class Crypt
/** /**
* 加密字符串 * 加密字符串
* @access public * @access public
* @param string $str 字符串 *
* @param $data
* @param string $key 加密key * @param string $key 加密key
* @param int $expire
*
* @return string * @return string
* @internal param string $str 字符串
*/ */
public static function encrypt($data, $key, $expire = 0) public static function encrypt($data, $key, $expire = 0)
{ {
@@ -46,9 +50,12 @@ class Crypt
/** /**
* 解密字符串 * 解密字符串
* @access public * @access public
* @param string $str 字符串 *
* @param $data
* @param string $key 加密key * @param string $key 加密key
*
* @return string * @return string
* @internal param string $str 字符串
*/ */
public static function decrypt($data, $key) public static function decrypt($data, $key)
{ {

View File

@@ -45,7 +45,11 @@ class Image
/** /**
* 初始化方法,用于实例化一个图片处理对象 * 初始化方法,用于实例化一个图片处理对象
*
* @param string $type 要使用的类库默认使用GD库 * @param string $type 要使用的类库默认使用GD库
* @param null $imgname
*
* @return resource
*/ */
public static function init($type = 'Gd', $imgname = null) public static function init($type = 'Gd', $imgname = null)
{ {

View File

@@ -11,6 +11,8 @@
namespace think\image\driver; namespace think\image\driver;
use Exception;
class Gd class Gd
{ {
/** /**
@@ -18,6 +20,9 @@ class Gd
* @var resource * @var resource
*/ */
private $im; private $im;
/**
* @var $git \think\image\driver\Gif
*/
private $gif; private $gif;
/** /**
* 图像信息包括width,height,type,mime,size * 图像信息包括width,height,type,mime,size
@@ -36,7 +41,11 @@ class Gd
/** /**
* 打开一张图像 * 打开一张图像
*
* @param string $imgname 图像路径 * @param string $imgname 图像路径
*
* @return $this
* @throws \Exception
*/ */
public function open($imgname) public function open($imgname)
{ {
@@ -50,7 +59,7 @@ class Gd
//检测图像合法性 //检测图像合法性
if (false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))) { if (false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))) {
throw new \Exception('非法图像文件'); throw new Exception('非法图像文件');
} }
//设置图像信息 //设置图像信息
@@ -78,14 +87,18 @@ class Gd
/** /**
* 保存图像 * 保存图像
*
* @param string $imgname 图像保存名称 * @param string $imgname 图像保存名称
* @param string $type 图像类型 * @param string $type 图像类型
* @param boolean $interlace 是否对JPEG类型图像设置隔行扫描 * @param boolean $interlace 是否对JPEG类型图像设置隔行扫描
*
* @return $this
* @throws Exception
*/ */
public function save($imgname, $type = null, $interlace = true) public function save($imgname, $type = null, $interlace = true)
{ {
if (empty($this->im)) { if (empty($this->im)) {
throw new \Exception('没有可以被保存的图像资源'); throw new Exception('没有可以被保存的图像资源');
} }
//自动获取图像类型 //自动获取图像类型
@@ -113,12 +126,13 @@ class Gd
/** /**
* 返回图像宽度 * 返回图像宽度
* @return integer 图像宽度 * @return int 图像宽度
* @throws Exception
*/ */
public function width() public function width()
{ {
if (empty($this->im)) { if (empty($this->im)) {
throw new \Exception('没有指定图像资源'); throw new Exception('没有指定图像资源');
} }
return $this->info['width']; return $this->info['width'];
@@ -126,12 +140,13 @@ class Gd
/** /**
* 返回图像高度 * 返回图像高度
* @return integer 图像高度 * @return int 图像高度
* @throws Exception
*/ */
public function height() public function height()
{ {
if (empty($this->im)) { if (empty($this->im)) {
throw new \Exception('没有指定图像资源'); throw new Exception('没有指定图像资源');
} }
return $this->info['height']; return $this->info['height'];
@@ -140,11 +155,12 @@ class Gd
/** /**
* 返回图像类型 * 返回图像类型
* @return string 图像类型 * @return string 图像类型
* @throws Exception
*/ */
public function type() public function type()
{ {
if (empty($this->im)) { if (empty($this->im)) {
throw new \Exception('没有指定图像资源'); throw new Exception('没有指定图像资源');
} }
return $this->info['type']; return $this->info['type'];
@@ -153,11 +169,12 @@ class Gd
/** /**
* 返回图像MIME类型 * 返回图像MIME类型
* @return string 图像MIME类型 * @return string 图像MIME类型
* @throws Exception
*/ */
public function mime() public function mime()
{ {
if (empty($this->im)) { if (empty($this->im)) {
throw new \Exception('没有指定图像资源'); throw new Exception('没有指定图像资源');
} }
return $this->info['mime']; return $this->info['mime'];
@@ -166,11 +183,12 @@ class Gd
/** /**
* 返回图像尺寸数组 0 - 图像宽度1 - 图像高度 * 返回图像尺寸数组 0 - 图像宽度1 - 图像高度
* @return array 图像尺寸 * @return array 图像尺寸
* @throws Exception
*/ */
public function size() public function size()
{ {
if (empty($this->im)) { if (empty($this->im)) {
throw new \Exception('没有指定图像资源'); throw new Exception('没有指定图像资源');
} }
return [$this->info['width'], $this->info['height']]; return [$this->info['width'], $this->info['height']];
@@ -178,17 +196,21 @@ class Gd
/** /**
* 裁剪图像 * 裁剪图像
*
* @param integer $w 裁剪区域宽度 * @param integer $w 裁剪区域宽度
* @param integer $h 裁剪区域高度 * @param integer $h 裁剪区域高度
* @param integer $x 裁剪区域x坐标 * @param integer $x 裁剪区域x坐标
* @param integer $y 裁剪区域y坐标 * @param integer $y 裁剪区域y坐标
* @param integer $width 图像保存宽度 * @param integer $width 图像保存宽度
* @param integer $height 图像保存高度 * @param integer $height 图像保存高度
*
* @return $this
* @throws Exception
*/ */
public function crop($w, $h, $x = 0, $y = 0, $width = null, $height = null) public function crop($w, $h, $x = 0, $y = 0, $width = null, $height = null)
{ {
if (empty($this->im)) { if (empty($this->im)) {
throw new \Exception('没有可以被裁剪的图像资源'); throw new Exception('没有可以被裁剪的图像资源');
} }
//设置保存尺寸 //设置保存尺寸
@@ -217,14 +239,18 @@ class Gd
/** /**
* 生成缩略图 * 生成缩略图
*
* @param integer $width 缩略图最大宽度 * @param integer $width 缩略图最大宽度
* @param integer $height 缩略图最大高度 * @param integer $height 缩略图最大高度
* @param integer $type 缩略图裁剪类型 * @param int $type 缩略图裁剪类型
*
* @return $this
* @throws Exception
*/ */
public function thumb($width, $height, $type = THINKIMAGE_THUMB_SCALE) public function thumb($width, $height, $type = THINKIMAGE_THUMB_SCALING)
{ {
if (empty($this->im)) { if (empty($this->im)) {
throw new \Exception('没有可以被缩略的图像资源'); throw new Exception('没有可以被缩略的图像资源');
} }
//原图宽度和高度 //原图宽度和高度
@@ -237,7 +263,7 @@ class Gd
case THINKIMAGE_THUMB_SCALING: case THINKIMAGE_THUMB_SCALING:
//原图尺寸小于缩略图尺寸则不进行缩略 //原图尺寸小于缩略图尺寸则不进行缩略
if ($w < $width && $h < $height) { if ($w < $width && $h < $height) {
return; return false;
} }
//计算缩放比例 //计算缩放比例
@@ -296,6 +322,8 @@ class Gd
//设置缩略图的坐标及宽度和高度 //设置缩略图的坐标及宽度和高度
$neww = $w * $scale; $neww = $w * $scale;
$newh = $h * $scale; $newh = $h * $scale;
$x = $this->info['width'] - $w;
$y = $this->info['height'] - $h;
$posx = ($width - $w * $scale) / 2; $posx = ($width - $w * $scale) / 2;
$posy = ($height - $h * $scale) / 2; $posy = ($height - $h * $scale) / 2;
@@ -322,7 +350,7 @@ class Gd
break; break;
default: default:
throw new \Exception('不支持的缩略图裁剪类型'); throw new Exception('不支持的缩略图裁剪类型');
} }
/* 裁剪图像 */ /* 裁剪图像 */
@@ -332,25 +360,29 @@ class Gd
/** /**
* 添加水印 * 添加水印
*
* @param string $source 水印图片路径 * @param string $source 水印图片路径
* @param integer $locate 水印位置 * @param int $locate 水印位置
* @param integer $alpha 水印透明度 *
* @return $this
* @throws Exception
* @internal param int $alpha 水印透明度
*/ */
public function water($source, $locate = THINKIMAGE_WATER_SOUTHEAST) public function water($source, $locate = THINKIMAGE_WATER_SOUTHEAST)
{ {
//资源检测 //资源检测
if (empty($this->im)) { if (empty($this->im)) {
throw new \Exception('没有可以被添加水印的图像资源'); throw new Exception('没有可以被添加水印的图像资源');
} }
if (!is_file($source)) { if (!is_file($source)) {
throw new \Exception('水印图像不存在'); throw new Exception('水印图像不存在');
} }
//获取水印图像信息 //获取水印图像信息
$info = getimagesize($source); $info = getimagesize($source);
if (false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))) { if (false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))) {
throw new \Exception('非法水印文件'); throw new Exception('非法水印文件');
} }
//创建水印图像资源 //创建水印图像资源
@@ -420,7 +452,7 @@ class Gd
if (is_array($locate)) { if (is_array($locate)) {
list($x, $y) = $locate; list($x, $y) = $locate;
} else { } else {
throw new \Exception('不支持的水印位置类型'); throw new Exception('不支持的水印位置类型');
} }
} }
@@ -446,23 +478,27 @@ class Gd
/** /**
* 图像添加文字 * 图像添加文字
*
* @param string $text 添加的文字 * @param string $text 添加的文字
* @param string $font 字体路径 * @param string $font 字体路径
* @param integer $size 字号 * @param integer $size 字号
* @param string $color 文字颜色 * @param string $color 文字颜色
* @param integer $locate 文字写入位置 * @param int $locate 文字写入位置
* @param integer $offset 文字相对当前位置的偏移量 * @param integer $offset 文字相对当前位置的偏移量
* @param integer $angle 文字倾斜角度 * @param integer $angle 文字倾斜角度
*
* @return $this
* @throws Exception
*/ */
public function text($text, $font, $size, $color = '#00000000', public function text($text, $font, $size, $color = '#00000000',
$locate = THINKIMAGE_WATER_SOUTHEAST, $offset = 0, $angle = 0) { $locate = THINKIMAGE_WATER_SOUTHEAST, $offset = 0, $angle = 0) {
//资源检测 //资源检测
if (empty($this->im)) { if (empty($this->im)) {
throw new \Exception('没有可以被写入文字的图像资源'); throw new Exception('没有可以被写入文字的图像资源');
} }
if (!is_file($font)) { if (!is_file($font)) {
throw new \Exception("不存在的字体文件:{$font}"); throw new Exception("不存在的字体文件:{$font}");
} }
//获取文字信息 //获取文字信息
@@ -536,7 +572,7 @@ class Gd
$x += $posx; $x += $posx;
$y += $posy; $y += $posy;
} else { } else {
throw new \Exception('不支持的文字位置类型'); throw new Exception('不支持的文字位置类型');
} }
} }
@@ -557,7 +593,7 @@ class Gd
$color[3] = 0; $color[3] = 0;
} }
} elseif (!is_array($color)) { } elseif (!is_array($color)) {
throw new \Exception('错误的颜色值'); throw new Exception('错误的颜色值');
} }
do { do {

View File

@@ -10,9 +10,6 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace think\image\driver; namespace think\image\driver;
use think\image\driver\GIFDecoder as GIFDecoder;
use think\image\driver\GIFEncoder as GIFEncoder;
class Gif class Gif
{ {
/** /**
@@ -44,7 +41,7 @@ class Gif
$de = new GIFDecoder($src); $de = new GIFDecoder($src);
$this->frames = $de->GIFGetFrames(); $this->frames = $de->GIFGetFrames();
$this->delays = $de->GIFGetDelays(); $this->delays = $de->GIFGetDelays();
} catch (Exception $e) { } catch (\Exception $e) {
throw new \Exception("解码GIF图片出错"); throw new \Exception("解码GIF图片出错");
} }
} }
@@ -53,7 +50,7 @@ class Gif
/** /**
* 设置或获取当前帧的数据 * 设置或获取当前帧的数据
* @param string $stream 二进制数据流 * @param string $stream 二进制数据流
* @return boolean 获取到的数据 * @return mixed 获取到的数据
*/ */
public function image($stream = null) public function image($stream = null)
{ {
@@ -85,7 +82,6 @@ class Gif
} }
} }
/* /*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: ::
@@ -110,8 +106,7 @@ class Gif
:: ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/ */
class GIFEncode
class GIFEncoder
{ {
public $GIF = "GIF89a"; /* GIF header 6 bytes */ public $GIF = "GIF89a"; /* GIF header 6 bytes */
public $VER = "GIFEncoder V2.05"; /* Encoder version */ public $VER = "GIFEncoder V2.05"; /* Encoder version */
@@ -139,7 +134,7 @@ class GIFEncoder
$GIF_src, $GIF_dly, $GIF_lop, $GIF_dis, $GIF_src, $GIF_dly, $GIF_lop, $GIF_dis,
$GIF_red, $GIF_grn, $GIF_blu, $GIF_mod $GIF_red, $GIF_grn, $GIF_blu, $GIF_mod
) { ) {
if (!is_array($GIF_src) && !is_array($GIF_tim)) { if (!is_array($GIF_src)) {
printf("%s: %s", $this->VER, $this->ERR['ERR00']); printf("%s: %s", $this->VER, $this->ERR['ERR00']);
exit(0); exit(0);
} }
@@ -175,11 +170,11 @@ class GIFEncoder
} }
} }
} }
GIFEncoder::GIFAddHeader(); self::GIFAddHeader();
for ($i = 0; $i < count($this->BUF); $i++) { for ($i = 0; $i < count($this->BUF); $i++) {
GIFEncoder::GIFAddFrames($i, $GIF_dly[$i]); self::GIFAddFrames($i, $GIF_dly[$i]);
} }
GIFEncoder::GIFAddFooter(); self::GIFAddFooter();
} }
/* /*
::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::
@@ -189,14 +184,13 @@ class GIFEncoder
*/ */
public function GIFAddHeader() public function GIFAddHeader()
{ {
$cmap = 0;
if (ord($this->BUF[0]{10}) & 0x80) { if (ord($this->BUF[0]{10}) & 0x80) {
$cmap = 3 * (2 << (ord($this->BUF[0]{10}) & 0x07)); $cmap = 3 * (2 << (ord($this->BUF[0]{10}) & 0x07));
$this->GIF .= substr($this->BUF[0], 6, 7); $this->GIF .= substr($this->BUF[0], 6, 7);
$this->GIF .= substr($this->BUF[0], 13, $cmap); $this->GIF .= substr($this->BUF[0], 13, $cmap);
$this->GIF .= "!\377\13NETSCAPE2.0\3\1" . GIFEncoder::GIFWord($this->LOP) . "\0"; $this->GIF .= "!\377\13NETSCAPE2.0\3\1" . self::GIFWord($this->LOP) . "\0";
} }
} }
/* /*
@@ -207,7 +201,7 @@ class GIFEncoder
*/ */
public function GIFAddFrames($i, $d) public function GIFAddFrames($i, $d)
{ {
$Locals_img='';
$Locals_str = 13 + 3 * (2 << (ord($this->BUF[$i]{10}) & 0x07)); $Locals_str = 13 + 3 * (2 << (ord($this->BUF[$i]{10}) & 0x07));
$Locals_end = strlen($this->BUF[$i]) - $Locals_str - 1; $Locals_end = strlen($this->BUF[$i]) - $Locals_str - 1;
@@ -239,6 +233,9 @@ class GIFEncoder
} }
switch ($Locals_tmp{0}) { switch ($Locals_tmp{0}) {
case "!": case "!":
/**
* @var string $Locals_img;
*/
$Locals_img = substr($Locals_tmp, 8, 10); $Locals_img = substr($Locals_tmp, 8, 10);
$Locals_tmp = substr($Locals_tmp, 18, strlen($Locals_tmp) - 18); $Locals_tmp = substr($Locals_tmp, 18, strlen($Locals_tmp) - 18);
break; break;
@@ -249,7 +246,7 @@ class GIFEncoder
} }
if (ord($this->BUF[$i]{10}) & 0x80 && $this->IMG > -1) { if (ord($this->BUF[$i]{10}) & 0x80 && $this->IMG > -1) {
if ($Global_len == $Locals_len) { if ($Global_len == $Locals_len) {
if (GIFEncoder::GIFBlockCompare($Global_rgb, $Locals_rgb, $Global_len)) { if (self::GIFBlockCompare($Global_rgb, $Locals_rgb, $Global_len)) {
$this->GIF .= ($Locals_ext . $Locals_img . $Locals_tmp); $this->GIF .= ($Locals_ext . $Locals_img . $Locals_tmp);
} else { } else {
$byte = ord($Locals_img{9}); $byte = ord($Locals_img{9});
@@ -460,7 +457,6 @@ class GIFDecoder
*/ */
public function GIFReadDescriptor() public function GIFReadDescriptor()
{ {
$GIF_screen = array();
GIFDecoder::GIFGetByte(9); GIFDecoder::GIFGetByte(9);
$GIF_screen = $this->GIF_buffer; $GIF_screen = $this->GIF_buffer;

View File

@@ -38,7 +38,7 @@ class Baidu extends Driver
* @param string $api 百度API * @param string $api 百度API
* @param string $param 调用API的额外参数 * @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET * @param string $method HTTP请求方法 默认为GET
* @return json * @return array
*/ */
public function call($api, $param = '', $method = 'GET') public function call($api, $param = '', $method = 'GET')
{ {

View File

@@ -15,6 +15,9 @@ namespace think;
class Parser class Parser
{ {
/**
* @var array $handler
*/
private static $handler = []; private static $handler = [];
// 解析内容 // 解析内容

View File

@@ -35,9 +35,12 @@ class Validate
/** /**
* 自动表单验证 * 自动表单验证
* @access protected * @access protected
*
* @param array $data 创建数据 * @param array $data 创建数据
* @param string $type 创建类型 * @param array $rule
* @return boolean *
* @return bool
* @internal param string $type 创建类型
*/ */
public function valid($data, $rule = []) public function valid($data, $rule = [])
{ {
@@ -96,7 +99,7 @@ class Validate
return false; return false;
} }
} }
return; return true;
} }
/** /**

View File

@@ -66,8 +66,9 @@ class App
// 执行操作 // 执行操作
if (!preg_match('/^[A-Za-z](\/|\.|\w)*$/', CONTROLLER_NAME)) { if (!preg_match('/^[A-Za-z](\/|\.|\w)*$/', CONTROLLER_NAME)) {
// 安全检测 // 安全检测
$instance = false; throw new Exception('[ ' . MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . Loader::parseName(str_replace('.', '\\', CONTROLLER_NAME), 1) . ' ] not exists');
} elseif ($config['action_bind_class']) { }
if ($config['action_bind_class']) {
$class = self::bindActionClass($config['empty_controller']); $class = self::bindActionClass($config['empty_controller']);
$instance = new $class; $instance = new $class;
// 操作绑定到类后 固定执行run入口 // 操作绑定到类后 固定执行run入口
@@ -77,9 +78,6 @@ class App
// 获取当前操作名 // 获取当前操作名
$action = ACTION_NAME . $config['action_suffix']; $action = ACTION_NAME . $config['action_suffix'];
} }
if (!$instance) {
throw new Exception('[ ' . MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . Loader::parseName(str_replace('.', '\\', CONTROLLER_NAME), 1) . ' ] not exists');
}
try { try {
// 操作方法开始监听 // 操作方法开始监听
@@ -213,7 +211,10 @@ class App
/** /**
* URL调度 * URL调度
* @access public * @access public
* @return void *
* @param $config
*
* @throws Exception
*/ */
public static function dispatch($config) public static function dispatch($config)
{ {

View File

@@ -0,0 +1,54 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think;
/**
* ThinkPHP Behavior基础类
* @category Think
* @package Think
* @subpackage Core
* @author liu21st <liu21st@gmail.com>
*/
abstract class Behavior {
// 行为参数 和配置参数设置相同
protected $options = array();
/**
* 架构函数
* @access public
*/
public function __construct() {
if(!empty($this->options)) {
foreach ($this->options as $name=>$val){
if(NULL !== C($name)) { // 参数已设置 则覆盖行为参数
$this->options[$name] = C($name);
}else{ // 参数未设置 则传入默认值到配置
C($name,$val);
}
}
array_change_key_case($this->options);
}
}
// 获取行为参数
public function __get($name){
return $this->options[strtolower($name)];
}
/**
* 执行行为 run方法是Behavior唯一的接口
* @access public
* @param mixed $params 行为参数
* @return void
*/
abstract public function run(&$params);
}

View File

@@ -28,7 +28,10 @@ class Apc
/** /**
* 架构函数 * 架构函数
*
* @param array $options 缓存参数 * @param array $options 缓存参数
*
* @throws Exception
* @access public * @access public
*/ */
public function __construct($options = []) public function __construct($options = [])
@@ -58,7 +61,7 @@ class Apc
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @param mixed $value 存储数据 * @param mixed $value 存储数据
* @param integer $expire 有效时间(秒) * @param integer $expire 有效时间(秒)
* @return boolen * @return bool
*/ */
public function set($name, $value, $expire = null) public function set($name, $value, $expire = null)
{ {
@@ -89,11 +92,12 @@ class Apc
return $result; return $result;
} }
/** /**删除缓存
* 删除缓存
* @access public * @access public
*
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @return boolen *
* @return bool|\string[]
*/ */
public function rm($name) public function rm($name)
{ {
@@ -103,7 +107,7 @@ class Apc
/** /**
* 清除缓存 * 清除缓存
* @access public * @access public
* @return boolen * @return bool
*/ */
public function clear() public function clear()
{ {

View File

@@ -72,7 +72,7 @@ class Memcache
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @param mixed $value 存储数据 * @param mixed $value 存储数据
* @param integer $expire 有效时间(秒) * @param integer $expire 有效时间(秒)
* @return boolen * @return bool
*/ */
public function set($name, $value, $expire = null) public function set($name, $value, $expire = null)
{ {
@@ -106,9 +106,11 @@ class Memcache
/** /**
* 删除缓存 * 删除缓存
* @access public *
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @return boolen * @param bool|false $ttl
*
* @return bool
*/ */
public function rm($name, $ttl = false) public function rm($name, $ttl = false)
{ {
@@ -121,7 +123,7 @@ class Memcache
/** /**
* 清除缓存 * 清除缓存
* @access public * @access public
* @return boolen * @return bool
*/ */
public function clear() public function clear()
{ {

View File

@@ -67,7 +67,7 @@ class Redis
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @param mixed $value 存储数据 * @param mixed $value 存储数据
* @param integer $expire 有效时间(秒) * @param integer $expire 有效时间(秒)
* @return boolen * @return boolean
*/ */
public function set($name, $value, $expire = null) public function set($name, $value, $expire = null)
{ {
@@ -107,7 +107,7 @@ class Redis
* 删除缓存 * 删除缓存
* @access public * @access public
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @return boolen * @return boolean
*/ */
public function rm($name) public function rm($name)
{ {
@@ -117,7 +117,7 @@ class Redis
/** /**
* 清除缓存 * 清除缓存
* @access public * @access public
* @return boolen * @return boolean
*/ */
public function clear() public function clear()
{ {

View File

@@ -65,7 +65,7 @@ class Secache
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @param mixed $value 存储数据 * @param mixed $value 存储数据
* @param integer $expire 有效时间(秒) * @param integer $expire 有效时间(秒)
* @return boolen * @return boolean
*/ */
public function set($name, $value) public function set($name, $value)
{ {

View File

@@ -26,6 +26,8 @@ class Simple
/** /**
* 架构函数 * 架构函数
* @access public * @access public
*
* @param array $options
*/ */
public function __construct($options = []) public function __construct($options = [])
{ {
@@ -68,12 +70,14 @@ class Simple
/** /**
* 写入缓存 * 写入缓存
* @access public * @access public
*
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @param mixed $value 存储数据 * @param mixed $value 存储数据
* @param int $expire 有效时间 0为永久 *
* @return boolen * @return bool
* @internal param int $expire 有效时间 0为永久
*/ */
public function set($name, $value, $expire = null) public function set($name, $value)
{ {
$filename = $this->filename($name); $filename = $this->filename($name);
// 缓存数据 // 缓存数据
@@ -88,7 +92,7 @@ class Simple
* 删除缓存 * 删除缓存
* @access public * @access public
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @return boolen * @return boolean
*/ */
public function rm($name) public function rm($name)
{ {
@@ -98,8 +102,8 @@ class Simple
/** /**
* 清除缓存 * 清除缓存
* @access public * @access public
* @param string $name 缓存变量名 * @return bool
* @return boolen * @internal param string $name 缓存变量名
*/ */
public function clear() public function clear()
{ {

View File

@@ -31,7 +31,10 @@ class Sqlite
/** /**
* 架构函数 * 架构函数
*
* @param array $options 缓存参数 * @param array $options 缓存参数
*
* @throws Exception
* @access public * @access public
*/ */
public function __construct($options = []) public function __construct($options = [])
@@ -74,7 +77,7 @@ class Sqlite
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @param mixed $value 存储数据 * @param mixed $value 存储数据
* @param integer $expire 有效时间(秒) * @param integer $expire 有效时间(秒)
* @return boolen * @return boolean
*/ */
public function set($name, $value, $expire = null) public function set($name, $value, $expire = null)
{ {
@@ -103,7 +106,7 @@ class Sqlite
* 删除缓存 * 删除缓存
* @access public * @access public
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @return boolen * @return boolean
*/ */
public function rm($name) public function rm($name)
{ {
@@ -116,7 +119,7 @@ class Sqlite
/** /**
* 清除缓存 * 清除缓存
* @access public * @access public
* @return boolen * @return boolean
*/ */
public function clear() public function clear()
{ {

View File

@@ -28,7 +28,10 @@ class Wincache
/** /**
* 架构函数 * 架构函数
*
* @param array $options 缓存参数 * @param array $options 缓存参数
*
* @throws Exception
* @access public * @access public
*/ */
public function __construct($options = []) public function __construct($options = [])
@@ -59,7 +62,7 @@ class Wincache
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @param mixed $value 存储数据 * @param mixed $value 存储数据
* @param integer $expire 有效时间(秒) * @param integer $expire 有效时间(秒)
* @return boolen * @return boolean
*/ */
public function set($name, $value, $expire = null) public function set($name, $value, $expire = null)
{ {
@@ -95,7 +98,7 @@ class Wincache
* 删除缓存 * 删除缓存
* @access public * @access public
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @return boolen * @return boolean
*/ */
public function rm($name) public function rm($name)
{ {
@@ -105,7 +108,7 @@ class Wincache
/** /**
* 清除缓存 * 清除缓存
* @access public * @access public
* @return boolen * @return boolean
*/ */
public function clear() public function clear()
{ {

View File

@@ -62,7 +62,7 @@ class Xcache
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @param mixed $value 存储数据 * @param mixed $value 存储数据
* @param integer $expire 有效时间(秒) * @param integer $expire 有效时间(秒)
* @return boolen * @return boolean
*/ */
public function set($name, $value, $expire = null) public function set($name, $value, $expire = null)
{ {
@@ -98,7 +98,7 @@ class Xcache
* 删除缓存 * 删除缓存
* @access public * @access public
* @param string $name 缓存变量名 * @param string $name 缓存变量名
* @return boolen * @return boolean
*/ */
public function rm($name) public function rm($name)
{ {
@@ -108,7 +108,7 @@ class Xcache
/** /**
* 清除缓存 * 清除缓存
* @access public * @access public
* @return boolen * @return boolean
*/ */
public function clear() public function clear()
{ {

View File

@@ -26,6 +26,8 @@ class Controller
/** /**
* 架构函数 初始化视图类 并采用内置模板引擎 * 架构函数 初始化视图类 并采用内置模板引擎
* @access public * @access public
*
* @param array $config
*/ */
public function __construct($config = []) public function __construct($config = [])
{ {
@@ -63,8 +65,8 @@ class Controller
$this->config[$key] = $config[$key]; $this->config[$key] = $config[$key];
} }
} }
return $this;
} }
return $this;
} }
/** /**

View File

@@ -57,9 +57,12 @@ abstract class rest
/** /**
* REST 调用 * REST 调用
* @access public * @access public
*
* @param string $method 方法名 * @param string $method 方法名
* @param array $args 参数 * @param array $args 参数
*
* @return mixed * @return mixed
* @throws \think\Exception
*/ */
public function _empty($method, $args) public function _empty($method, $args)
{ {

View File

@@ -51,17 +51,19 @@ class Cookie
{ {
if (empty($prefix)) { if (empty($prefix)) {
return self::$config['prefix']; return self::$config['prefix'];
} else {
self::$config['prefix'] = $prefix;
} }
self::$config['prefix'] = $prefix;
} }
/** /**
* Cookie 设置、获取、删除 * Cookie 设置、获取、删除
*
* @param string $name cookie名称 * @param string $name cookie名称
* @param mixed $value cookie值 * @param mixed $value cookie值
* @param mixed $options cookie参数 * @param null $option
*
* @return mixed * @return mixed
* @internal param mixed $options cookie参数
*/ */
public static function set($name, $value = '', $option = null) public static function set($name, $value = '', $option = null)
{ {

View File

@@ -32,7 +32,10 @@ class Mongo extends Driver
/** /**
* 架构函数 读取数据库配置信息 * 架构函数 读取数据库配置信息
* @access public * @access public
* @param array $config 数据库配置数组 *
* @param array|string $config 数据库配置数组
*
* @throws Exception
*/ */
public function __construct($config = '') public function __construct($config = '')
{ {
@@ -45,11 +48,18 @@ class Mongo extends Driver
$this->config['params'] = []; $this->config['params'] = [];
} }
} }
$this->config = $config;
} }
/** /**
* 连接数据库方法 * 连接数据库方法
* @access public * @access public
*
* @param string $config
* @param int $linkNum
*
* @return
* @throws Exception
*/ */
public function connect($config = '', $linkNum = 0) public function connect($config = '', $linkNum = 0)
{ {
@@ -71,10 +81,12 @@ class Mongo extends Driver
/** /**
* 切换当前操作的Db和Collection * 切换当前操作的Db和Collection
* @access public * @access public
*
* @param string $collection collection * @param string $collection collection
* @param string $db db * @param string $db db
* @param boolean $master 是否主服务器 * @param boolean $master 是否主服务器
* @return void *
* @throws Exception
*/ */
public function switchCollection($collection, $db = '', $master = true) public function switchCollection($collection, $db = '', $master = true)
{ {
@@ -137,9 +149,12 @@ class Mongo extends Driver
/** /**
* 执行语句 * 执行语句
* @access public * @access public
*
* @param string $code sql指令 * @param string $code sql指令
* @param array $args 参数 * @param array $args 参数
*
* @return mixed * @return mixed
* @throws Exception
*/ */
public function execute($code, $args = []) public function execute($code, $args = [])
{ {
@@ -185,10 +200,13 @@ class Mongo extends Driver
/** /**
* 插入记录 * 插入记录
* @access public * @access public
*
* @param mixed $data 数据 * @param mixed $data 数据
* @param array $options 参数表达式 * @param array $options 参数表达式
* @param boolean $replace 是否replace * @param boolean $replace 是否replace
* @return false | integer *
* @return false|int
* @throws Exception
*/ */
public function insert($data, $options = [], $replace = false) public function insert($data, $options = [], $replace = false)
{ {
@@ -222,9 +240,12 @@ class Mongo extends Driver
/** /**
* 插入多条记录 * 插入多条记录
* @access public * @access public
*
* @param array $dataList 数据 * @param array $dataList 数据
* @param array $options 参数表达式 * @param array $options 参数表达式
*
* @return bool * @return bool
* @throws Exception
*/ */
public function insertAll($dataList, $options = []) public function insertAll($dataList, $options = [])
{ {
@@ -246,8 +267,11 @@ class Mongo extends Driver
/** /**
* 生成下一条记录ID 用于自增非MongoId主键 * 生成下一条记录ID 用于自增非MongoId主键
* @access public * @access public
*
* @param string $pk 主键名 * @param string $pk 主键名
* @return integer *
* @return int
* @throws Exception
*/ */
public function getMongoNextId($pk) public function getMongoNextId($pk)
{ {
@@ -268,9 +292,12 @@ class Mongo extends Driver
/** /**
* 更新记录 * 更新记录
* @access public * @access public
*
* @param mixed $data 数据 * @param mixed $data 数据
* @param array $options 表达式 * @param array $options 表达式
*
* @return bool * @return bool
* @throws Exception
*/ */
public function update($data, $options) public function update($data, $options)
{ {

View File

@@ -42,6 +42,9 @@ class Mysql extends Driver
/** /**
* 取得数据表的字段信息 * 取得数据表的字段信息
* @access public * @access public
* @param $tableName
*
* @return array
*/ */
public function getFields($tableName) public function getFields($tableName)
{ {
@@ -68,6 +71,10 @@ class Mysql extends Driver
/** /**
* 取得数据库的表信息 * 取得数据库的表信息
* @access public * @access public
*
* @param string $dbName
*
* @return array
*/ */
public function getTables($dbName = '') public function getTables($dbName = '')
{ {

View File

@@ -94,6 +94,10 @@ class Oracle extends Driver
/** /**
* 取得数据表的字段信息 * 取得数据表的字段信息
* @access public * @access public
*
* @param $tableName
*
* @return array
*/ */
public function getFields($tableName) public function getFields($tableName)
{ {
@@ -121,8 +125,10 @@ class Oracle extends Driver
/** /**
* 取得数据库的表信息(暂时实现取得用户表信息) * 取得数据库的表信息(暂时实现取得用户表信息)
* @access public * @access public
* @return array
* @internal param string $dbName
*/ */
public function getTables($dbName = '') public function getTables()
{ {
$result = $this->query("select table_name from user_tables"); $result = $this->query("select table_name from user_tables");
$info = []; $info = [];
@@ -151,10 +157,11 @@ class Oracle extends Driver
} }
return $limitStr ? ' WHERE ' . $limitStr : ''; return $limitStr ? ' WHERE ' . $limitStr : '';
} }
/** /**
* 设置锁机制 * 设置锁机制
* @access protected * @access protected
* @param bool|false $lock
*
* @return string * @return string
*/ */
protected function parseLock($lock = false) protected function parseLock($lock = false)

View File

@@ -332,6 +332,7 @@ class Lite
* 并显示当前的SQL语句 * 并显示当前的SQL语句
* @access public * @access public
* @return string * @return string
* @throws Exception
*/ */
public function error() public function error()
{ {

View File

@@ -84,9 +84,11 @@ class Error
/** /**
* 错误输出 * 错误输出
*
* @param mixed $error 错误 * @param mixed $error 错误
* @param int $errno 错误代码 * @param int $code
* @return void *
* @internal param int $errno 错误代码
*/ */
public static function halt($error, $code = 1) public static function halt($error, $code = 1)
{ {
@@ -99,7 +101,8 @@ class Error
$data['code'] = $code; $data['code'] = $code;
$data['msg'] = $message; $data['msg'] = $message;
$data['time'] = NOW_TIME; $data['time'] = NOW_TIME;
exit(Response::returnData($data)); Response::returnData($data);
exit();
} }
$e = []; $e = [];
if (APP_DEBUG) { if (APP_DEBUG) {

View File

@@ -160,9 +160,15 @@ class Input
/** /**
* 获取系统变量 支持过滤和默认值 * 获取系统变量 支持过滤和默认值
* @access public * @access public
* @param string $method 输入数据类型 *
* @param array $args 参数 [key,filter,default] * @param $name
* @param $input
* @param $filter
* @param $default
*
* @return mixed * @return mixed
* @internal param string $method 输入数据类型
* @internal param array $args 参数 [key,filter,default]
*/ */
private static function getData($name, $input, $filter, $default) private static function getData($name, $input, $filter, $default)
{ {

View File

@@ -229,12 +229,14 @@ class Loader
return false; return false;
} }
} }
/** /**
* 取得对象实例 支持调用类的静态方法 * 取得对象实例 支持调用类的静态方法
*
* @param string $class 对象类名 * @param string $class 对象类名
* @param string $method 类的静态方法名 * @param string $method 类的静态方法名
* @return object *
* @return mixed
* @throws Exception
*/ */
public static function instance($class, $method = '') public static function instance($class, $method = '')
{ {
@@ -244,7 +246,7 @@ class Loader
if (class_exists($class)) { if (class_exists($class)) {
$o = new $class(); $o = new $class();
if (!empty($method) && method_exists($o, $method)) { if (!empty($method) && method_exists($o, $method)) {
$_instance[$identify] = call_user_func_array([ & $o, $method]); $_instance[$identify] = call_user_func_array([ & $o, $method],[]);
} else { } else {
$_instance[$identify] = $o; $_instance[$identify] = $o;
} }

View File

@@ -30,10 +30,11 @@ class Log
/** /**
* 记录日志 并且会过滤未经设置的级别 * 记录日志 并且会过滤未经设置的级别
* @access public * @access public
*
* @param string $message 日志信息 * @param string $message 日志信息
* @param string $level 日志级别 * @param string $level 日志级别
* @param boolean $record 是否强制记录 *
* @return void * @internal param bool $record 是否强制记录
*/ */
public static function record($message, $level = 'INFO') public static function record($message, $level = 'INFO')
{ {

View File

@@ -36,9 +36,12 @@ class MongoModel extends \Think\Model
/** /**
* 利用__call方法实现一些特殊的Model方法 * 利用__call方法实现一些特殊的Model方法
* @access public * @access public
*
* @param string $method 方法名称 * @param string $method 方法名称
* @param array $args 调用参数 * @param array $args 调用参数
*
* @return mixed * @return mixed
* @throws \think\Exception
*/ */
public function __call($method, $args) public function __call($method, $args)
{ {
@@ -54,7 +57,6 @@ class MongoModel extends \Think\Model
return $this->where($where)->getField($args[1]); return $this->where($where)->getField($args[1]);
} else { } else {
throw new \think\Exception(__CLASS__ . ':' . $method . Lang::get('_METHOD_NOT_EXIST_')); throw new \think\Exception(__CLASS__ . ':' . $method . Lang::get('_METHOD_NOT_EXIST_'));
return;
} }
} }

View File

@@ -179,9 +179,12 @@ class Session
/** /**
* 判断session数据 * 判断session数据
*
* @param string $name session名称 * @param string $name session名称
* @param mixed $value session值 * @param string $prefix
* @return boolean *
* @return bool
* @internal param mixed $value session值
*/ */
public static function has($name, $prefix = '') public static function has($name, $prefix = '')
{ {

View File

@@ -75,8 +75,13 @@ class TagLib
/** /**
* TagLib标签属性分析 返回标签属性数组 * TagLib标签属性分析 返回标签属性数组
* @access public * @access public
* @param string $tagStr 标签内容 *
* @param $attr
* @param $tag
*
* @return array * @return array
* @throws Exception
* @internal param string $tagStr 标签内容
*/ */
public function parseXmlAttr($attr, $tag) public function parseXmlAttr($attr, $tag)
{ {
@@ -92,7 +97,7 @@ class TagLib
} }
$xml = (array) ($xml->tag->attributes()); $xml = (array) ($xml->tag->attributes());
$array = array_change_key_case($xml['@attributes']); $array = array_change_key_case($xml['@attributes']);
if ($array) { if (!is_array($array)) return [];
$tag = strtolower($tag); $tag = strtolower($tag);
if (isset($this->tags[$tag]['attr'])) { if (isset($this->tags[$tag]['attr'])) {
$attrs = explode(',', $this->tags[$tag]['attr']); $attrs = explode(',', $this->tags[$tag]['attr']);
@@ -109,9 +114,9 @@ class TagLib
} }
} }
} }
return $array; return $array;
} }
}
/** /**
* 解析条件表达式 * 解析条件表达式

View File

@@ -113,10 +113,14 @@ class View
/** /**
* 解析和获取模板内容 用于输出 * 解析和获取模板内容 用于输出
* @access public * @access public
*
* @param string $template 模板文件名或者内容 * @param string $template 模板文件名或者内容
* @param array $vars 模板输出变量 * @param array $vars 模板输出变量
* @param string $cache_id 模板缓存标识 * @param string $cache_id 模板缓存标识
* @param bool $renderContent
*
* @return string * @return string
* @throws Exception
*/ */
public function fetch($template = '', $vars = [], $cache_id = '', $renderContent = false) public function fetch($template = '', $vars = [], $cache_id = '', $renderContent = false)
{ {