/** * 自定义异常处理 * @access public * @param mixed $e 异常对象 */ public static function appException($e) { $error = array(); $error['message'] = $e->getMessage(); $trace = $e->getTrace(); if ('E' == $trace[0]['function']) { $error['file'] = $trace[0]['file']; $error['line'] = $trace[0]['line']; } else { $error['file'] = $e->getFile(); $error['line'] = $e->getLine(); } $error['trace'] = $e->getTraceAsString(); Logs::debug("appException", $error); }
private function errorlog($msg = '') { $error = date('Y-m-d H:i:s') . ":\n" . $this->errorno() . ":\nmsg:" . $this->error() . $msg . ";\n"; Logs::debug('mysql.txt', $error); /* $file = APP_LOG_PATH . 'sql/mysql.txt'; file_put_contents($file, "{$error}\n", @filesize($file)<1024*1024 ? FILE_APPEND : null); */ die('DB Invalid!!!'); }
public static function getConversionRules($className) { $className = strtolower($className); if (!array_key_exists($className, self::$conversions)) { Logs::debug('Registered models:', array_keys(self::$conversions)); throw new Exception('Unregistered model:' . $className); } return self::$conversions[$className]; }
private function executeRequest($httpMethod, $url, $queryParams = null, $requestHeaders = null, $contentType = "application/x-www-form-urlencoded", $specialAuth = null) { if ($queryParams == null) { $queryParams = array(); } if ($requestHeaders == null) { $requestHeaders = array(); } // Check if the charset is specified in the content-type: if (strpos($contentType, 'charset') === false) { $charset = OneApiConfigurator::getCharset(); if (!$charset) { $charset = 'utf-8'; } $contentType .= '; charset=' . $charset; } $sendHeaders = array('Content-Type: ' . $contentType); foreach ($requestHeaders as $key => $value) { $sendHeaders[] = $key . ': ' . $value; } if ($httpMethod === 'GET') { if (sizeof($queryParams) > 0) { $url .= '?' . $this->buildQuery($queryParams); } } $opts = array(CURLOPT_FRESH_CONNECT => 1, CURLOPT_CONNECTTIMEOUT => 60, CURLOPT_TIMEOUT => 120, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 3, CURLOPT_USERAGENT => 'OneApi-php-' . self::VERSION, CURLOPT_CUSTOMREQUEST => $httpMethod, CURLOPT_URL => $url, CURLOPT_HTTPHEADER => $sendHeaders); if ($specialAuth) { $opts[CURLOPT_HTTPHEADER][] = 'Authorization: App ' . $specialAuth; } else { if ($this->oneApiAuthentication && $this->oneApiAuthentication->ibssoToken) { // Token based authentication (one request per login request): $opts[CURLOPT_HTTPHEADER][] = 'Authorization: IBSSO ' . $this->oneApiAuthentication->ibssoToken; } else { // Basic authorization: $opts[CURLOPT_USERPWD] = $this->username . ':' . $this->password; } } Logs::debug('Executing ', $httpMethod, ' to ', $url); if (sizeof($queryParams) > 0 && ($httpMethod == 'POST' || $httpMethod == 'PUT')) { $httpBody = null; if (strpos($contentType, 'x-www-form-urlencoded')) { $httpBody = $this->buildQuery($queryParams); } else { if (strpos($contentType, 'json')) { $httpBody = json_encode($queryParams); } } Logs::debug('Http body:', $httpBody); $opts[CURLOPT_POSTFIELDS] = $httpBody; } $ch = curl_init(); curl_setopt_array($ch, $opts); $result = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (curl_errno($ch) != 0) { throw new Exception(curl_error($ch)); } $isSuccess = 200 <= $code && $code < 300; curl_close($ch); Logs::debug('Response code ', $code); Logs::debug('isSuccess:', $isSuccess); Logs::debug('Result:', $result); return array($isSuccess, $result); }