phprs\util\Verify::isTrue PHP Метод

isTrue() публичный статический Метод

如果判断不为true,抛出异常
public static isTrue ( boolean $var, string | Exception $msg = null ) : unknown
$var boolean
$msg string | Exception
Результат unknown
    public static function isTrue($var, $msg = null)
    {
        if (!$var) {
            if ($msg === null || is_string($msg)) {
                Logger::warning($msg);
                throw new \Exception($msg);
            } else {
                Logger::warning($msg->__toString());
                throw $msg;
            }
        } else {
            return $var;
        }
    }

Usage Example

Пример #1
0
 private function getImpl()
 {
     if ($this->redis === null) {
         $this->redis = new \Redis();
     }
     if (!$this->redis->isConnected()) {
         $this->redis->connect($this->host, $this->port);
     }
     if (!empty($this->user) && !empty($this->pwd)) {
         Verify::isTrue($this->redis->auth($this->user . ":" . $this->pwd), $this->redis->getLastError());
     }
     return $this->redis;
 }
All Usage Examples Of phprs\util\Verify::isTrue