PSR规范调整

This commit is contained in:
thinkphp
2015-10-04 13:05:15 +08:00
parent 1cfb3704c6
commit 27e724bb3c
135 changed files with 9426 additions and 11556 deletions

View File

@@ -11,9 +11,10 @@
namespace think;
class Hook {
class Hook
{
static private $tags = [];
private static $tags = [];
/**
* 动态添加行为扩展到某个标签
@@ -21,11 +22,12 @@ class Hook {
* @param mixed $behavior 行为名称
* @return void
*/
static public function add($tag,$behavior) {
if(is_array($behavior)) {
self::$tags[$tag] = array_merge(self::$tags[$tag],$behavior);
}else{
self::$tags[$tag][] = $behavior;
public static function add($tag, $behavior)
{
if (is_array($behavior)) {
self::$tags[$tag] = array_merge(self::$tags[$tag], $behavior);
} else {
self::$tags[$tag][] = $behavior;
}
}
@@ -34,8 +36,9 @@ class Hook {
* @param array $tags 标签行为
* @return void
*/
static public function import($tags) {
self::$tags = array_merge(self::$tags,$tags);
public static function import($tags)
{
self::$tags = array_merge(self::$tags, $tags);
}
/**
@@ -44,23 +47,24 @@ class Hook {
* @param mixed $params 传入参数
* @return void
*/
static public function listen($tag, &$params=null) {
if(isset(self::$tags[$tag])) {
public static function listen($tag, &$params = null)
{
if (isset(self::$tags[$tag])) {
foreach (self::$tags[$tag] as $name) {
if(APP_DEBUG){
Debug::remark('behavior_start','time');
if (APP_DEBUG) {
Debug::remark('behavior_start', 'time');
}
$result = self::exec($name, $tag,$params);
$result = self::exec($name, $tag, $params);
if(APP_DEBUG){
Debug::remark('behavior_end','time');
Log::record('Run '.$name.' [ RunTime:'.Debug::getUseTime('behavior_start','behavior_end').'s ]','INFO');
if (APP_DEBUG) {
Debug::remark('behavior_end', 'time');
Log::record('Run ' . $name . ' [ RunTime:' . Debug::getUseTime('behavior_start', 'behavior_end') . 's ]', 'INFO');
}
if(false === $result) {
if (false === $result) {
// 如果返回false 则中断行为执行
return ;
return;
}
}
}
@@ -70,15 +74,16 @@ class Hook {
/**
* 执行某个行为
* @param string $name 行为名称
* @param string $tag 方法名(标签名)
* @param string $tag 方法名(标签名)
* @param Mixed $params 传人的参数
* @return void
*/
static public function exec($name, $tag,&$params=null) {
if($name instanceof \Closure) {
public static function exec($name, $tag, &$params = null)
{
if ($name instanceof \Closure) {
return $name($params);
}
$addon = new $name();
return method_exists($addon,$tag) ? $addon->$tag($params): $addon->run($params);
$addon = new $name();
return method_exists($addon, $tag) ? $addon->$tag($params) : $addon->run($params);
}
}