diff --git a/bootstrap-dev.php b/bootstrap-dev.php index fabd957..1d9a8a3 100644 --- a/bootstrap-dev.php +++ b/bootstrap-dev.php @@ -1,5 +1,25 @@ debug(__METHOD__ . ' get cache', [ + 'name' => $name, + 'default' => $default, + ]); + if ( ! isset($this->_cache[$name])) { + Base::getLog()->debug(__METHOD__ . ' cache not found, return default value', [ + 'name' => $name, + 'default' => $default, + ]); return $default; } $data = Arr::get($this->_cache, $name); // 判断过期时间 + $current = time(); $expired = Arr::get($data, 'expired'); - if (time() > $expired) + if ($current > $expired) { + Base::getLog()->debug(__METHOD__ . ' cache is expired', [ + 'name' => $name, + 'current' => $current, + 'expired' => $expired, + ]); $this->remove($name); return $default; } @@ -78,9 +94,17 @@ public function get($name, $default = null) */ public function set($name, $value, $expired = null) { + // 过期时间自动加上当前时间戳 + $expired = time() + $expired; + + Base::getLog()->debug(__METHOD__ . ' save cache', [ + 'name' => $name, + 'type' => gettype($value), + 'expired' => $expired, + ]); $this->_cache[$name] = [ 'value' => $value, - 'expired' => time() + $expired, + 'expired' => $expired, ]; return true; } @@ -93,6 +117,9 @@ public function set($name, $value, $expired = null) */ public function remove($name) { + Base::getLog()->debug(__METHOD__ . ' remove cache', [ + 'name' => $name, + ]); unset($this->_cache[$name]); return true; } diff --git a/src/Component/Flash.php b/src/Component/Flash.php index 691dd06..949fb2b 100644 --- a/src/Component/Flash.php +++ b/src/Component/Flash.php @@ -131,7 +131,7 @@ public function save() */ public function loadMessages() { - Base::getLog()->debug(__METHOD__ . ' load flash messages'); + Base::getLog()->debug(__METHOD__ . ' load flash messages from session'); if ($value = Base::getSession()->get($this->settings['key'])) { $this->messages['prev'] = $value; diff --git a/src/Component/Http.php b/src/Component/Http.php index 01e76c9..7e41f68 100644 --- a/src/Component/Http.php +++ b/src/Component/Http.php @@ -292,7 +292,7 @@ class Http extends Component ]; /** - * @var string 默认HTTP协议 + * @var string 默认HTTP协议 */ public $protocol = 'HTTP/1.1'; diff --git a/src/Component/Log.php b/src/Component/Log.php index 2ec8771..6d7b3a0 100644 --- a/src/Component/Log.php +++ b/src/Component/Log.php @@ -6,6 +6,7 @@ /** * 日志记录组件 + * [!!] 此LOG组件对自身操作不做记录 * * @package tourze\Base\Component */ diff --git a/src/Component/Mail.php b/src/Component/Mail.php index 2de844f..9dcf50f 100644 --- a/src/Component/Mail.php +++ b/src/Component/Mail.php @@ -2,6 +2,7 @@ namespace tourze\Base\Component; +use tourze\Base\Base; use tourze\Base\Component; /** @@ -111,6 +112,13 @@ public function setMessage($message) */ public function send($to = null, $subject = null, $message = null, $from = null) { + Base::getLog()->debug(__METHOD__ . ' call send mail method', [ + 'to' => $to, + 'subject' => $subject, + 'message' => $message, + 'from' => $from, + ]); + if ($to === null) { $to = $this->to; @@ -133,7 +141,17 @@ public function send($to = null, $subject = null, $message = null, $from = null) $to = implode(', ', $to); } + Base::getLog()->debug(__METHOD__ . ' prepare to send mail', [ + 'to' => $to, + 'subject' => $subject, + 'message' => $message, + 'from' => $from, + ]); + $result = @mail($to, $subject, $message, 'From: ' . $from); + Base::getLog()->debug(__METHOD__ . ' send mail result', [ + 'result' => $result, + ]); $this->to = null; $this->subject = null; diff --git a/src/Component/Session.php b/src/Component/Session.php index 9b0c805..4376ec9 100644 --- a/src/Component/Session.php +++ b/src/Component/Session.php @@ -45,6 +45,7 @@ public function start() */ public function id($id = null) { + Base::getLog()->debug(__METHOD__ . ' get session id'); return session_id($id); } diff --git a/src/Config.php b/src/Config.php index 9ee4c80..1685d48 100644 --- a/src/Config.php +++ b/src/Config.php @@ -50,6 +50,8 @@ public static function load($path, $reload = false) } $cacheKey = md5(json_encode($path)); + + // 如果有缓存并且可以不重新加载,那么就直接返回 if ( ! $reload && isset(self::$_pathCache[$cacheKey])) { return self::$_pathCache[$cacheKey]; diff --git a/src/Exception/BaseException.php b/src/Exception/BaseException.php index 9e348e0..152bcfc 100755 --- a/src/Exception/BaseException.php +++ b/src/Exception/BaseException.php @@ -8,9 +8,7 @@ /** * 最基础的异常类,使用[I18n]来做异常信息的翻译 * - * @package Base - * @category Exceptions - * @author YwiSax + * @package tourze\Base\Exception */ class BaseException extends Exception implements ExceptionInterface { diff --git a/src/Exception/ComponentClassNotFoundException.php b/src/Exception/ComponentClassNotFoundException.php index b0df880..6b4970a 100644 --- a/src/Exception/ComponentClassNotFoundException.php +++ b/src/Exception/ComponentClassNotFoundException.php @@ -2,6 +2,11 @@ namespace tourze\Base\Exception; +/** + * 组件类名不存在时抛出异常 + * + * @package tourze\Base\Exception + */ class ComponentClassNotFoundException extends BaseException { diff --git a/src/Exception/ComponentNotFoundException.php b/src/Exception/ComponentNotFoundException.php index 1b5fbf6..86f5420 100644 --- a/src/Exception/ComponentNotFoundException.php +++ b/src/Exception/ComponentNotFoundException.php @@ -2,6 +2,11 @@ namespace tourze\Base\Exception; +/** + * 指定组件不存在时抛出异常 + * + * @package tourze\Base\Exception + */ class ComponentNotFoundException extends BaseException { diff --git a/src/Exception/EmptyCollectionException.php b/src/Exception/EmptyCollectionException.php deleted file mode 100644 index 7cca1b0..0000000 --- a/src/Exception/EmptyCollectionException.php +++ /dev/null @@ -1,8 +0,0 @@ - 'mary', 'children' => ['fred', 'paul', 'sally', 'jane']] * - * @param array $array1 初始数组 - * @param array $array2,... 要合并的数组 - * @return array + * @param array $array1 初始数组 + * @param array $array2,... 要合并的数组 + * @return array */ public static function merge($array1, $array2) { @@ -549,35 +547,29 @@ public static function overwrite($array1, $array2) * $result = call_user_func_array($func, $params); * * @param string $str callback字符串 - * @return array function, params + * @return array function, params */ public static function callback($str) { - // Overloaded as parts are found $params = null; // command[param,param] if (preg_match('/^([^\(]*+)\((.*)\)$/', $str, $match)) { - // command $command = $match[1]; - if ($match[2] !== '') { - // param,param $params = preg_split('/(? 'bar'], true); * - * @copyright https://github.com/akira-cn/JKit - * @param mixed $obj 被copy到的对象 - * @param array $hash 关联数组 - * @param boolean $override 是否覆盖对象上已有属性 - * @return mixed 被copy到的对象 + * @copyright https://github.com/akira-cn/JKit + * @param mixed $obj 被copy到的对象 + * @param array $hash 关联数组 + * @param bool $override 是否覆盖对象上已有属性 + * @return mixed 被copy到的对象 */ public static function mix($obj, $hash, $override = false) { diff --git a/src/Helper/Cookie.php b/src/Helper/Cookie.php index b42908e..e10ea11 100755 --- a/src/Helper/Cookie.php +++ b/src/Helper/Cookie.php @@ -8,9 +8,7 @@ /** * Cookie助手类 * - * @package Base - * @category Helpers - * @author YwiSax + * @package tourze\Base\Helper */ class Cookie { @@ -133,8 +131,7 @@ public static function delete($name) */ public static function salt($name, $value) { - // Determine the user agent - $agent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : 'unknown'; + $agent = strtolower(Arr::get($_SERVER, 'HTTP_USER_AGENT', 'unknown')); return sha1($agent . $name . $value . Cookie::$salt); } diff --git a/src/Helper/Date.php b/src/Helper/Date.php index a36e129..a786620 100644 --- a/src/Helper/Date.php +++ b/src/Helper/Date.php @@ -1,15 +1,14 @@