Skip to content

Commit

Permalink
1. 修正大部分注释
Browse files Browse the repository at this point in the history
2. 删除无用异常类
3. 增加部分日志记录
  • Loading branch information
tourze committed Sep 5, 2015
1 parent 0752a95 commit 8be8c5b
Show file tree
Hide file tree
Showing 38 changed files with 196 additions and 149 deletions.
24 changes: 22 additions & 2 deletions bootstrap-dev.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
<?php

use tourze\Base\Base;
use tourze\Base\Config;
use tourze\Base\I18n;
use tourze\Base\Message;

Base::$cacheDir = __DIR__ . DIRECTORY_SEPARATOR . 'cache';
if (is_file(__DIR__ . '/vendor/autoload.php'))
{
require __DIR__ . '/vendor/autoload.php';
}

// 检测是否在SAE中
if ( ! defined('IN_SAE'))
{
define('IN_SAE', function_exists('sae_debug'));
}

// 指定配置加载目录
Config::addPath(__DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR);

// 语言文件目录
I18n::addPath(__DIR__ . DIRECTORY_SEPARATOR . 'i18n' . DIRECTORY_SEPARATOR);

// Message目录
Message::addPath(__DIR__ . DIRECTORY_SEPARATOR . 'message' . DIRECTORY_SEPARATOR);
25 changes: 7 additions & 18 deletions src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Base extends Object
{

/**
* @const string 当前框架版本
* @const string 当前框架版本
*/
const VERSION = 'beta';

Expand All @@ -35,17 +35,17 @@ class Base extends Object
public static $locale = 'en_US.utf-8';

/**
* @var string 默认输出的内容类型
* @var string 默认输出的内容类型
*/
public static $contentType = 'text/html';

/**
* @var string 输入输出编码
* @var string 输入输出编码
*/
public static $charset = 'utf-8';

/**
* @var string 当前服务器名称
* @var string 当前服务器名称
*/
public static $serverName = '';

Expand All @@ -55,27 +55,17 @@ class Base extends Object
public static $hostNames = [];

/**
* @var string 当前应用所在路径,相对于web根目录
* @var string 当前应用所在路径,相对于web根目录
*/
public static $baseUrl = '/';

/**
* @var string 缺省文件名称
* @var string 缺省文件名称
*/
public static $indexFile = false;

/**
* @var string 文件缓存使用的目录
*/
public static $cacheDir;

/**
* @var int 自带缓存的默认生命周期
*/
public static $cacheLife = 60;

/**
* @var boolean 自定义X-Powered-By
* @var bool 自定义X-Powered-By
*/
public static $expose = false;

Expand All @@ -88,7 +78,6 @@ class Base extends Object
* 单次请求的初始化
*
* @throws BaseException
* @return void
*/
public function init()
{
Expand Down
31 changes: 29 additions & 2 deletions src/Component/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace tourze\Base\Component;

use tourze\Base\Base;
use tourze\Base\Component;
use tourze\Base\Helper\Arr;

Expand Down Expand Up @@ -49,17 +50,32 @@ public function setExpired($expired)
*/
public function get($name, $default = null)
{
Base::getLog()->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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Flash.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class Http extends Component
];

/**
* @var string 默认HTTP协议
* @var string 默认HTTP协议
*/
public $protocol = 'HTTP/1.1';

Expand Down
1 change: 1 addition & 0 deletions src/Component/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* 日志记录组件
* [!!] 此LOG组件对自身操作不做记录
*
* @package tourze\Base\Component
*/
Expand Down
18 changes: 18 additions & 0 deletions src/Component/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace tourze\Base\Component;

use tourze\Base\Base;
use tourze\Base\Component;

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Component/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function start()
*/
public function id($id = null)
{
Base::getLog()->debug(__METHOD__ . ' get session id');
return session_id($id);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/BaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
/**
* 最基础的异常类,使用[I18n]来做异常信息的翻译
*
* @package Base
* @category Exceptions
* @author YwiSax
* @package tourze\Base\Exception
*/
class BaseException extends Exception implements ExceptionInterface
{
Expand Down
5 changes: 5 additions & 0 deletions src/Exception/ComponentClassNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace tourze\Base\Exception;

/**
* 组件类名不存在时抛出异常
*
* @package tourze\Base\Exception
*/
class ComponentClassNotFoundException extends BaseException
{

Expand Down
5 changes: 5 additions & 0 deletions src/Exception/ComponentNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace tourze\Base\Exception;

/**
* 指定组件不存在时抛出异常
*
* @package tourze\Base\Exception
*/
class ComponentNotFoundException extends BaseException
{

Expand Down
8 changes: 0 additions & 8 deletions src/Exception/EmptyCollectionException.php

This file was deleted.

4 changes: 3 additions & 1 deletion src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace tourze\Base\Exception;

/**
* 异常接口
* 异常类接口
*
* @package tourze\Base\Exception
*/
interface ExceptionInterface
{
Expand Down
5 changes: 5 additions & 0 deletions src/Exception/HelperException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace tourze\Base\Exception;

/**
* 助手类抛出的基础异常
*
* @package tourze\Base\Exception
*/
class HelperException extends BaseException
{
}
8 changes: 0 additions & 8 deletions src/Exception/ImmutableKeyException.php

This file was deleted.

5 changes: 5 additions & 0 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace tourze\Base\Exception;

/**
* 无效参数时抛出的异常
*
* @package tourze\Base\Exception
*/
class InvalidArgumentException extends BaseException
{

Expand Down
5 changes: 5 additions & 0 deletions src/Exception/InvalidCallException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace tourze\Base\Exception;

/**
* 无效调用时抛出的异常
*
* @package tourze\Base\Exception
*/
class InvalidCallException extends BaseException
{
}
5 changes: 5 additions & 0 deletions src/Exception/InvalidCallbackException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace tourze\Base\Exception;

/**
* 遇到无效回调时抛出的异常
*
* @package tourze\Base\Exception
*/
class InvalidCallbackException extends BaseException
{
}
5 changes: 5 additions & 0 deletions src/Exception/InvalidConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace tourze\Base\Exception;

/**
* 遇到无效配置时抛出的异常
*
* @package tourze\Base\Exception
*/
class InvalidConfigException extends BaseException
{
}
6 changes: 5 additions & 1 deletion src/Exception/InvalidRangeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace tourze\Base\Exception;

/**
* 无效范围
*
* @package tourze\Base\Exception
*/
class InvalidRangeException extends BaseException
{

}
8 changes: 0 additions & 8 deletions src/Exception/KeyNotFoundException.php

This file was deleted.

Loading

0 comments on commit 8be8c5b

Please sign in to comment.