You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

96 lines
2.2 KiB

<?php
namespace apps\base\hooks;
class AppHook {
/**
* 开始时间
* @var integer
*/
public $startTime = 0;
/**
* 框架启动
* @return void
*/
public function appBegin() {
$this->startTime = microtime(true);
}
/**
* 框架结束
* @return void
*/
public function appEnd() {
//echo microtime(true) - $this->startTime ;
}
/**
* 框架错误
* @param objcet $e 错误对象
* @return viod
*/
public function appError($e) {
if(404 == $e->getCode()) {
$action = 'error404';
}else{
$action = 'error';
}
A('base/Error','controllers')->$action($e);
}
/**
* 路由解析
* @param array $rewriteRule 路由规则
* @param boolean $rewriteOn 路由开关
* @return void
*/
public function routeParseUrl($rewriteRule, $rewriteOn) {
}
/**
* 方法开始
* @param objcet $obj 操作对象
* @param string $action 方法名
* @return void
*/
public function actionBefore($obj, $action) {
$this->_initialize();
}
/**
* 方法结束
* @param objcet $obj 操作对象
* @param string $action 方法名
* @return void
*/
public function actionAfter($obj, $action) {
}
/**
* 初始化应用
*/
private function _initialize() {
$initialize_path = APP_PATH . 'config/';
$initialize_cache = ROOT_PATH . 'data/caches/app/' . APP_NAME . '/';
if (!file_exists($initialize_cache)) {
if (!@mkdir($initialize_cache, 0777, true)) {
throw new \Exception("Can not create dir '{$initialize_cache}'", 500);
}
}
if (!is_writable($initialize_cache)) @chmod($initialize_cache, 0777);
if (file_exists($initialize_path . 'initialize.php') && (!file_exists($initialize_cache . 'installed.lock') && !file_exists($initialize_path . 'installed.lock'))) {
$initialize = require $initialize_path . 'initialize.php';
if (isset($initialize['db'])) {
$init_sql = is_string($initialize['db']) ? array($initialize['db']) : $initialize['db'];
$db = new \base\Model();
foreach ($init_sql as $sql) {
$db->query($sql);
}
}
file_put_contents($initialize_cache . 'installed.lock', 'lock');
}
}
}