Пример #1
0
 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);
 }
Пример #2
0
 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;
 }
Пример #3
0
 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;
 }
Пример #4
0
 /**
  * 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;
         }
     }
 }
Пример #5
0
 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;
 }
Пример #6
0
 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');
 }
Пример #7
0
 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;
 }
Пример #8
0
 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);
 }