convertExceptionToString() public static method

Converts an exception into a simple string.
public static convertExceptionToString ( Exception $exception ) : string
$exception Exception the exception being converted
return string the string representation of the exception.
Esempio n. 1
0
 public function init()
 {
     parent::init();
     $this->parseParams();
     //初始化解析参数
     //重写exception handler
     set_exception_handler(function ($e) {
         //捕获错误信息
         $this->exception = \yii\base\ErrorHandler::convertExceptionToString($e);
     });
     //重写register_shutdown
     register_shutdown_function(function () {
         //非致命错误脚本结束写日志
         $task = isset($this->data['task']) ? $this->data['task'] : '';
         $task_id = isset($this->data['info']['task_id']) ? $this->data['info']['task_id'] : 0;
         $orgcode = isset($this->data['info']['orgcode']) ? $this->data['info']['orgcode'] : '';
         $task_type = isset($this->data['info']['task_type']) ? $this->data['info']['task_type'] : '';
         $start_time = isset($this->data['info']['start_time']) ? $this->data['info']['start_time'] : '';
         $msg = [];
         $msg['info'] = $this->loginfo['info'];
         $msg['exitStatus'] = \Yii::$app->response->exitStatus;
         if (isset($this->data['retry_times'])) {
             $msg['retry_times'] = $this->data['retry_times'];
         }
         $end_time = date('Y-m-d H:i:s');
         if ($this->exception) {
             $msg['exitStatus'] = 1;
             $IsSuccess = 0;
         } elseif ($msg['exitStatus'] == 0) {
             $IsSuccess = 1;
         } elseif ($msg['exitStatus'] == 1) {
             $IsSuccess = 0;
         }
         $this->task_log($task_id, $orgcode, $task, $task_type, $start_time, $end_time, $msg, $IsSuccess, $this->exception);
         if ($IsSuccess) {
             //成功则更细
             $this->updateTaskStatus($task_id, ['progress' => 0, 'retry_times' => 0]);
             //更新任务状态
         } else {
             //失败则更新
             $retry_times = isset($this->data['retry_times']) ? $this->data['retry_times'] : 0;
             //                 $this->updateTaskStatus($task_id,['retry_times'=>$retry_times]); //更新任务状态,重试次数
             $this->updateTaskStatus($task_id, ['progress' => 0, 'retry_times' => 0]);
             //更新任务状态
         }
         if ($this->exception) {
             echo $this->exception, PHP_EOL;
             exit(1);
         }
     });
 }
Esempio n. 2
0
 public function init()
 {
     parent::init();
     $this->parseParams();
     //初始化解析参数
     //重写exception handler
     set_exception_handler(function ($e) {
         //捕获错误信息,stack信息
         $this->exception = \yii\base\ErrorHandler::convertExceptionToString($e);
     });
     //重写register_shutdown
     register_shutdown_function(function () {
         //非致命错误脚本结束写日志
         //完成处理log对象
         if ($this->exception) {
             //异常处理模式跟`return 1`一样
             echo $this->exception, PHP_EOL;
             exit(1);
         }
     });
 }
Esempio n. 3
0
 /**
  * Dispatches the logged messages to [[targets]].
  * @param array $messages the logged messages
  * @param boolean $final whether this method is called at the end of the current application
  */
 public function dispatch($messages, $final)
 {
     $targetErrors = [];
     foreach ($this->targets as $target) {
         if ($target->enabled) {
             try {
                 $target->collect($messages, $final);
             } catch (\Exception $e) {
                 $target->enabled = false;
                 $targetErrors[] = ['Unable to send log via ' . get_class($target) . ': ' . ErrorHandler::convertExceptionToString($e), Logger::LEVEL_WARNING, __METHOD__, microtime(true), []];
             }
         }
     }
     if (!empty($targetErrors)) {
         $this->dispatch($targetErrors, true);
     }
 }
Esempio n. 4
0
 /**
  * Session write handler.
  * Do not call this method directly.
  * @param string $id session ID
  * @param string $data session data
  * @return boolean whether session write is successful
  */
 public function writeSession($id, $data)
 {
     // exception must be caught in session write handler
     // http://us.php.net/manual/en/function.session-set-save-handler.php
     try {
         $this->db->getCollection($this->sessionCollection)->update(['id' => $id], $this->composeFields($id, $data), ['upsert' => true]);
     } catch (\Exception $e) {
         $exception = ErrorHandler::convertExceptionToString($e);
         // its too late to use Yii logging here
         error_log($exception);
         echo $exception;
         return false;
     }
     return true;
 }
Esempio n. 5
0
 /**
  * Rotates image if need.
  * @param string $readFilePath path to file that must be checked and rotated (if need).
  * @param string|null|false $extension extension for new temp file.
  * Default is false, meaning extension must be parsed from `$readFilePath` file.
  * @return string|null new temp file path, or null if rotating is not necessary.
  */
 protected function rotateImage($readFilePath, $extension = false)
 {
     try {
         $result = ImageHelper::normalizeRotating($readFilePath);
         if (!$result) {
             return null;
         }
         if ($extension === false) {
             $extension = $this->parseFileExtension($readFilePath);
         }
         $tempFile = FileSystemHelper::getNewTempFilename($extension);
         $result->save($tempFile, $this->saveOptions);
         return $tempFile;
     } catch (\Exception $ex) {
         Yii::error('Cannot normalize rotating. ' . ErrorHandler::convertExceptionToString($ex), __METHOD__);
         return null;
     }
 }