warning() public static method

warning log
public static warning ( string $msg ) : void
$msg string
return void
Example #1
0
 /**
  *
  * @param \Exception|string $e
  * @throws unknown
  */
 public static function e($e)
 {
     if ($e === null || is_string($e)) {
         Logger::warning($e);
         throw new \Exception($e);
     } else {
         Logger::warning($e->__toString());
         throw $e;
     }
 }
Example #2
0
 /**
  * modify user's information
  * @route({"POST","/current"}) 
  * 
  * @param({"password", "$._POST.password"}) modify password, optional
  * @param({"alias", "$._POST.alias"})  modify alias, optional
  * @param({"avatar", "$._FILES.avatar.tmp_name"})  modify avatar, optional
  * @param({"token", "$._COOKIE.token"}) used for auth
  *
  * @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden", {"error":"Forbidden"}}) invalid cookie
  * 
  * @throws({"AliasConflict","status", "409 Conflict", {"error":"AliasConflict"}}) alias conflict
  * 
  */
 public function updateUser($token, $alias = null, $password = null, $avatar = null)
 {
     $token = $this->factory->create('Tokens')->getToken($token);
     Verify::isTrue(isset($token['uid']) && $token['uid'] != 0, new Forbidden("invalid uid {$token['uid']}"));
     if ($avatar) {
         $avatar = $this->uploadAvatar($avatar);
     }
     $uid = $token['uid'];
     $pdo = $this->db;
     $pdo->beginTransaction();
     try {
         if ($alias || $avatar) {
             $sets = array();
             $params = array();
             if ($alias) {
                 $res = Sql::select('uid')->from('pre_common_member_profile')->where('realname = ? AND uid <> ?', $alias, $uid)->forUpdate()->get($pdo);
                 Verify::isTrue(count($res) == 0, new AliasConflict("alias {$alias} conflict"));
                 $params['realname'] = $alias;
             }
             if ($avatar) {
                 $params['avatar'] = $avatar;
             }
             Sql::update('pre_common_member_profile')->setArgs($params)->where('uid = ?', $uid)->exec($pdo);
         }
         if ($password !== null) {
             Sql::update('uc_members')->setArgs(['password' => $password, 'salt' => ''])->where('uid=?', $uid)->exec($pdo);
         }
         $pdo->commit();
     } catch (Exception $e) {
         Logger::warning("updateUser({$uid}) failed with " . $e->getMessage());
         $pdo->rollBack();
         throw $e;
     }
 }
Example #3
0
 /**
  * 加载api类
  * @param array $routes
  * @param string $class_file
  * @param string $class_name
  * @param string $method
  * @return void
  */
 private function loadApi(&$routes, $class_file, $class_name, $method = null)
 {
     Verify::isTrue(is_file($class_file), $class_file . ' is not an exist file');
     Logger::debug("attempt to load api: {$class_name}, {$class_file}");
     $this->class_loader->addClass($class_name, $class_file);
     $api = null;
     if ($this->ignore_load_error) {
         try {
             $api = $this->factory->create('phprs\\Container', array($class_name, $method), null, null);
         } catch (\Exception $e) {
             Logger::warning("load api: {$class_name}, {$class_file} failed with " . $e->getMessage());
             return;
         }
     } else {
         $api = $this->factory->create('phprs\\Container', array($class_name, $method), null, null);
     }
     foreach ($api->routes as $http_method => $route) {
         if (!isset($routes[$http_method])) {
             $routes[$http_method] = new HttpRouterEntries();
         }
         $cur = $routes[$http_method];
         foreach ($route as $entry) {
             list($uri, $invoke, $strict) = $entry;
             $realpath = preg_replace('/\\/+/', '/', '/' . $uri);
             $strict = $strict === null ? $this->default_strict_matching : $strict;
             Verify::isTrue($cur->insert($realpath, $invoke, $strict), "repeated path {$realpath}");
             Logger::debug("api: {$http_method} {$realpath} => {$class_name}::{$entry[1]->method_name} ok, strict:{$strict}");
         }
     }
     Logger::debug("load api: {$class_name}, {$class_file} ok");
 }