public function add($level, $msg) { //as a logger, i won't throw any exception to interrupt your program if (!isset($this->_conf[$level])) { if (auto::isDebugMode() || auto::isDevMode()) { auto::dqueue('<font color=red>warning</font>', 'log got no conf for level:' . $level); } else { return false; } } $rotation = $this->_getRotationByLevel($level); if (!$rotation) { $rotation = 'default'; } $dir = $this->_conf[$level]['path']; if (!is_dir($dir)) { $mk = @mkdir($dir, 777, true); if (!$mk) { auto::isDebugMode() && auto::dqueue('<font color=red>warning</font>', 'failed for make log dir:' . $dir); return false; } } $logFile = $dir . DS . $rotation . '.log'; if (!is_scalar($msg)) { $msg = var_export($msg, true); } $msg = date('Y-m-d H:i:s') . "\t" . $level . "\t" . $msg . "\n"; file_put_contents($logFile, $msg, FILE_APPEND); }
public static function topDeal404($e) { if (!auto::isDebugMode() && !auto::isCliMode()) { echo '404, page not found!'; } else { //debugmode or in sapi mode var_dump($e->getMessage(), $e->getCode()); } }
public function __call($funcName, $arguments) { auto::isDebugMode() && ($_debugMicrotime = microtime(true)); if (!$this->_memcached) { throw new exception_cache('connection error!' . (auto::isDebugMode() ? var_export($this->_confs, true) : ''), exception_cache::type_server_connection_error); } $ret = call_user_func_array(array($this->_memcached, $funcName), $arguments); auto::isDebugMode() && auto::dqueue(__CLASS__ . '::' . $funcName, 'cost ' . (microtime(true) - $_debugMicrotime) . 's, arguments: ' . var_export($arguments, true)); return $ret; }
public static function topDeal($e) { if (!auto::isDebugMode() && !auto::isCliMode()) { //response::top404(); echo 'error occured!'; } else { //debugmode or in sapi mode var_dump($e->getMessage(), $e->getCode()); } }
public function connect($type = null) { if ($type === null) { throw new exception_mysqlpdo('no type specified for mysqlpdo connection!', exception_mysqlpdo::type_conf_error); } auto::isDebugMode() && ($_debugMicrotime = microtime(true)); //$type = self::TYPE_SERVER_MASTER; //every time run "new db_mysqlpdo($conf)->connect($type)" would reconnect the mysql database! $this->_pdoCon = $this->_getPdo($type); auto::isDebugMode() && auto::dqueue(__METHOD__, 'cost ' . (microtime(true) - $_debugMicrotime) . 's, alias: ' . $this->_alias . ',conf ' . var_export($this->_confs, true)); return $this->_pdoCon; }
/** * run plugins of this type * @param type $type */ public static function run($type) { if (isset(self::$_plugins[$type]) && is_array(self::$_plugins[$type])) { while (self::$_plugins[$type]) { $plugin = array_shift(self::$_plugins[$type]); auto::isDebugMode() && ($_debugMicrotime = microtime(true)); auto::isDebugMode() && auto::dqueue(__METHOD__ . " ('{$plugin}') ", 'start ---->>>>'); self::_execPlugin($plugin); auto::isDebugMode() && auto::dqueue(__METHOD__ . " ('{$plugin}') ", 'end,<<<<---- cost ' . (microtime(true) - $_debugMicrotime) . 's'); self::$_pluginsHasRun[] = $plugin; } } }
public function fetch($path = '') { auto::isDebugMode() && ($_debugMicrotime = microtime(true)); if ($path) { $ret = $this->_render->fetch($path); auto::isDebugMode() && auto::dqueue(__METHOD__ . '(' . $path . ')', 'cost ' . (microtime(true) - $_debugMicrotime) . 's '); return $ret; } $dir = dispatcher::instance()->getModuleName(); $controller = dispatcher::instance()->getControllerName(); $action = dispatcher::instance()->getActionName(); if (dispatcher::instance()->getPathDeep() == dispatcher::path_deep3) { $path = $dir . DS . $controller . DS . $action; } else { $path = $controller . DS . $action; } $ret = $this->_render->fetch($path); auto::isDebugMode() && auto::dqueue(__METHOD__ . '(' . $path . ')', 'cost ' . (microtime(true) - $_debugMicrotime) . 's '); return $ret; }
public function run() { plugin::run('before_run'); auto::isDebugMode() && ($_debugMicrotime = microtime(true)); if (self::$_pathDeep == self::path_deep3) { $className = 'controller_' . self::$_currentModule . '_' . self::$_currentController; } else { $className = 'controller_' . self::$_currentController; } if (!class_exists($className)) { throw new exception_404('controller not exist: ' . $className, exception_404::type_controller_not_exist); } $actionName = self::$_currentAction . 'Action'; auto::isDebugMode() && auto::dqueue(__METHOD__ . '(' . $className . '->' . $actionName . ')', 'start ---->>>>'); $class = new ReflectionClass($className); if ($class->isAbstract()) { throw new exception_404('can not run abstract class: ' . $className, exception_404::type_controller_is_abstract); } $method = $class->getMethod($actionName); if (!$method || !$method->isPublic()) { throw new exception_404('no public method ' . $method . ' exist in class:' . $className, exception_404::type_action_not_public); } $method->invoke($class->newInstance()); auto::isDebugMode() && auto::dqueue(__METHOD__ . '(' . $className . '->' . $actionName . ')', 'end,<<<<---- cost ' . (microtime(true) - $_debugMicrotime) . 's'); plugin::run('after_run'); }
public function structure($fullType = false) { auto::isDebugMode() && ($_debugMicrotime = microtime(true)); if (isset(self::$_tableStructure[$this->_dbAlias][$this->_table])) { return self::$_tableStructure[$this->_dbAlias][$this->_table]; } $sql = "DESC " . $this->_table; $this->_lastQuery = $sql; $sth = $this->_getPdoByMethodName()->prepare($sql); $res = $sth->execute(array()); if (!$res) { $this->_raiseError('select query failed~', exception_mysqlpdo::type_query_error); } $dt = $sth->fetchAll(PDO::FETCH_ASSOC); if (!$fullType && is_array($dt)) { $fields = array(); foreach ($dt as $v) { $fields[] = $v['Field']; } $dt = $fields; } self::$_tableStructure[$this->_dbAlias][$this->_table] = $dt; auto::isDebugMode() && auto::dqueue(__METHOD__, 'cost ' . (microtime(true) - $_debugMicrotime) . 's of query: ' . var_export($this->_lastQuery, true)); return $dt; }
public function render($path) { auto::isDebugMode() && auto::dqueue('render data for ' . $path, '<pre>' . rico::export($this->data) . '</pre>'); $data = $this->fetch($path); response::output($data); }
public static function shutdownCall() { if (self::$shutdownFunction) { call_user_func(self::$shutdownFunction); return; } if (!auto::isDebugMode()) { return; } //do not output debug info when ajax request if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { return; } $rn = "\n"; $hasNotRunPlugins = plugin::getHasNotRunPlugin(plugin::type_before_run); if ($hasNotRunPlugins) { $msg = array('title' => '<font color=red><b>Warning: some plugins NOT RUN(maybe "exit()" used! in your program?)</b></font>', 'msg' => var_export($hasNotRunPlugins, true)); array_unshift(self::$_debugQueue, $msg); } $hasNotRunPlugins2 = plugin::getHasNotRunPlugin(plugin::type_after_run); if ($hasNotRunPlugins2) { $msg = array('title' => '<font color=red><b>Warning: some plugins NOT RUN(maybe "exit()" used in your program?)</b></font>', 'msg' => var_export($hasNotRunPlugins2, true)); array_unshift(self::$_debugQueue, $msg); } //total cost auto::$runtimeEnd = microtime(true); $msg = array('title' => 'total runtime cost', 'msg' => auto::$runtimeEnd - auto::$runtimeStart); array_unshift(self::$_debugQueue, $msg); if (auto::isCliMode()) { $output = ' #################### debug info : #################### (you can turn this off by "auto::setDebugMode(false)") '; foreach (self::$_debugQueue as $item) { $tstr = ' >>>>>>' . $item['title'] . '>>>>>> ' . $item['msg']; $output .= $tstr; } $output .= ' '; } else { $output = '<style>.autophp_debug_span{width:100%;display:block;border-bottom: dashed 1px gray;margin: 3px 0 3px 0;padding:3px 0 3px 0;font-size: 14px;font-family: Arial}</style> <fieldset> <span class="autophp_debug_span"><b>debug info : </b> (you can turn this off by "auto::setDebugMode(false)")</span>'; foreach (self::$_debugQueue as $item) { $tstr = '<span class="autophp_debug_span"><font color=blue>' . $item['title'] . ': </font>' . $item['msg'] . '</span>'; $output .= $tstr; } $output .= '</fieldset>'; } echo $output; }