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,10 +11,11 @@
namespace think;
class Debug {
static protected $info = [];
static protected $mem = [];
class Debug
{
protected static $info = [];
protected static $mem = [];
/**
* 记录时间(微秒)和内存使用情况
@@ -22,10 +23,11 @@ class Debug {
* @param mixed $value 标记值 留空则取当前 time 表示仅记录时间 否则同时记录时间和内存
* @return mixed
*/
static public function remark($name,$value='') {
// 记录时间和内存使用
self::$info[$name] = is_float($value) ? $value : microtime(true);
if('time' != $value ) {
public static function remark($name, $value = '')
{
// 记录时间和内存使用
self::$info[$name] = is_float($value) ? $value : microtime(true);
if ('time' != $value) {
self::$mem['mem'][$name] = is_float($value) ? $value : memory_get_usage();
self::$mem['peak'][$name] = memory_get_peak_usage();
}
@@ -38,11 +40,12 @@ class Debug {
* @param integer|string $dec 小数位
* @return mixed
*/
static public function getUseTime($start,$end,$dec=6) {
if(!isset(self::$info[$end])) {
self::$info[$end] = microtime(true);
public static function getUseTime($start, $end, $dec = 6)
{
if (!isset(self::$info[$end])) {
self::$info[$end] = microtime(true);
}
return number_format((self::$info[$end]-self::$info[$start]),$dec);
return number_format((self::$info[$end] - self::$info[$start]), $dec);
}
/**
@@ -52,39 +55,41 @@ class Debug {
* @param integer|string $dec 小数位
* @return mixed
*/
static public function getUseMem($start,$end,$dec=2) {
if(!isset(self::$mem['mem'][$end])) {
self::$mem['mem'][$end] = memory_get_usage();
public static function getUseMem($start, $end, $dec = 2)
{
if (!isset(self::$mem['mem'][$end])) {
self::$mem['mem'][$end] = memory_get_usage();
}
$size = self::$mem['mem'][$end]-self::$mem['mem'][$start];
$a = ['B', 'KB', 'MB', 'GB', 'TB'];
$pos = 0;
$size = self::$mem['mem'][$end] - self::$mem['mem'][$start];
$a = ['B', 'KB', 'MB', 'GB', 'TB'];
$pos = 0;
while ($size >= 1024) {
$size /= 1024;
$pos++;
}
return round($size,$dec)." ".$a[$pos];
return round($size, $dec) . " " . $a[$pos];
}
/**
* 统计内存峰值情况
* @param string $start 开始标签
* @param string $end 结束标签
* @param integer|string $dec 小数位
* @param integer|string $dec 小数位
* @return mixed
*/
static public function getMemPeak($start,$end,$dec=2) {
if(!isset(self::$mem['peak'][$end])) {
self::$mem['peak'][$end] = memory_get_peak_usage() ;
public static function getMemPeak($start, $end, $dec = 2)
{
if (!isset(self::$mem['peak'][$end])) {
self::$mem['peak'][$end] = memory_get_peak_usage();
}
$size = self::$mem['peak'][$end]-self::$mem['peak'][$start];
$a = ['B', 'KB', 'MB', 'GB', 'TB'];
$pos = 0;
$size = self::$mem['peak'][$end] - self::$mem['peak'][$start];
$a = ['B', 'KB', 'MB', 'GB', 'TB'];
$pos = 0;
while ($size >= 1024) {
$size /= 1024;
$pos++;
}
return round($size,$dec)." ".$a[$pos];
return round($size, $dec) . " " . $a[$pos];
}
/**
@@ -94,24 +99,25 @@ class Debug {
* @param string $label 标签 默认为空
* @return void|string
*/
static public function dump($var, $echo=true, $label=null) {
$label = ($label === null) ? '' : rtrim($label) . ':';
public static function dump($var, $echo = true, $label = null)
{
$label = (null === $label) ? '' : rtrim($label) . ':';
ob_start();
var_dump($var);
$output = ob_get_clean();
$output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output);
if(IS_CLI) {
$output = PHP_EOL . $label. $output . PHP_EOL;
}else{
if (IS_CLI) {
$output = PHP_EOL . $label . $output . PHP_EOL;
} else {
if (!extension_loaded('xdebug')) {
$output = htmlspecialchars($output, ENT_QUOTES);
}
$output = '<pre>' . $label . $output . '</pre>';
}
if ($echo) {
echo($output);
echo ($output);
return null;
}else{
} else {
return $output;
}
}