/** * Allows applications to modify the entity associated with the item being * created before persisting it. * * @param object $entity */ protected function prePersistEntity($entity) { if ($entity instanceof Gallery) { if (null !== $entity->getFile()) { $entity->setPath($this->uploadFile($entity->getFile())); $entity->setFile(); } } $entity->setCreatedAt(new \DateTime(date('Y-m-d H:i:s'))); $entity->setModifiedAt(new \DateTime(date('Y-m-d H:i:s'))); $entity->setCreatedBy(12); }
/** * Test add file * * @param array $file - list of file data * * @dataProvider providerFile * * @return array */ public function testAddFile($file) { $this->uploader->addFile($file); $file = $this->uploader->getFile(); $this->assertArrayHasKey('name', $file); $this->assertArrayHasKey('mime', $file); $this->assertArrayHasKey('path', $file); $this->assertEquals('TestImage.png', $file['name']); $this->assertEquals(File\MimeType::PNG, $file['mime']); $this->assertEquals('TestImages/TestImage.png', $file['path']); $this->assertFileExists($file['path']); return $file; }
/** * @todo: catch getPrevious() exception * * @param object $exception Exception * * @return multitype:multitype:Ambigous <NULL, unknown> */ public function getExceptionArray($exception) { $_trace = []; foreach ($exception->getTrace() as $key => $item) { $_trace[$key] = ['file' => isset($item['file']) ? $item['file'] : null, 'line' => isset($item['line']) ? $item['line'] : null, 'function' => isset($item['function']) ? $item['function'] : null, 'class' => isset($item['class']) ? $item['class'] : null]; } return ['message' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'requestUri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null, 'serverName' => isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null, 'date' => date('d.m.Y H:i'), 'trace' => $_trace, 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null, 'get' => Yii::$app->request->get(), 'post' => Yii::$app->request->post()]; }
/** * Обработчик непойманых исключений * * @param object $exception - объект исключения */ public static function handleException($exception) { ob_end_clean_all(); $detals = array(); $detals['File'] = str_replace([ROOT_PATH, '\\'], ['', '/'], $exception->getFile()); $detals['Line'] = $exception->getLine(); $detals['Msg'] = $exception->getMessage(); Error::e503($detals); }
/** * Gets Information (message, code, file, line, trace) of an Exception. * * @param object $oE Exception object. * @return string */ public static function getInfoExcept($oE) { $sDebug = $oE->getMessage(); $sDebug .= '<br />'; $sDebug = $oE->getCode(); $sDebug .= '<br />'; $sDebug = $oE->getFile(); $sDebug .= '<br />'; $sDebug = $oE->getLine(); $sDebug .= '<br />'; $sDebug .= $oE->getTraceAsString(); return $sDebug; }
/** * Метод для записи логов * @param object $e Объект класса Exception * @return bool Вернет истину если файл запишется */ public function writeLog($e) { $datetime = date('d/m/y H:i:s'); $msg = date('d/m/y H:i:s') . '||'; $msg .= 'Код: ' . $e->getCode() . '||'; $msg .= 'Сообщение: ' . $e->getMessage() . '||'; $msg .= 'Линия: ' . $e->getLine() . '||'; $msg .= 'Файл: ' . $e->getFile() . "\n"; if (!file_put_contents(Config::LOGS, $msg, FILE_APPEND | LOCK_EX)) { return false; } else { return true; } }
/** * Render the backtrace * * @return string The contents of the backtrace */ public function renderBacktrace() { $contents = null; $backtrace = $this->error->getTrace(); if (is_array($backtrace)) { ob_start(); $j = 1; $html = array(); $html[] = '<table class="backtrace">'; $html[] = ' <caption>Call stack</caption>'; $html[] = ' <thead>'; $html[] = ' <tr>'; $html[] = ' <th scope="col">#</th>'; $html[] = ' <th scope="col">Function</th>'; $html[] = ' <th scope="col">Location</th>'; $html[] = ' </tr>'; $html[] = ' </thead>'; $html[] = ' <tbody>'; $html[] = ' <tr>'; $html[] = ' <th scope="row">0</th>'; $html[] = ' <td><span class="msg">!! ' . $this->error->getMessage() . ' !!</span></td>'; $html[] = ' <td><span class="fl">' . $this->rooted($this->error->getFile()) . '</span>:<span class="ln">' . $this->error->getLine() . '</span></td>'; $html[] = ' </tr>'; for ($i = count($backtrace) - 1; $i >= 0; $i--) { $html[] = ' <tr>'; $html[] = ' <th scope="row">' . $j . '</th>'; if (isset($backtrace[$i]['class'])) { $html[] = ' <td><span class="cls">' . $backtrace[$i]['class'] . '</span><span class="opn">' . $backtrace[$i]['type'] . '</span><span class="mtd">' . $backtrace[$i]['function'] . '</span>()</td>'; } else { $html[] = ' <td><span class="fnc">' . $backtrace[$i]['function'] . '</span>()</td>'; } if (isset($backtrace[$i]['file'])) { $html[] = ' <td><span class="fl">' . $this->rooted($backtrace[$i]['file']) . '</span>:<span class="ln">' . $backtrace[$i]['line'] . '</span></td>'; } else { $html[] = ' <td> </td>'; } $html[] = ' </tr>'; $j++; } $html[] = ' </tbody>'; $html[] = '</table>'; echo "\n" . implode("\n", $html) . "\n"; $contents = ob_get_contents(); ob_end_clean(); } return $contents; }
/** * User exception handler * * @param object $exc hold error data * @return void **/ public static function exceptionHandler($exc) { $errno = $exc->getCode(); $errmsg = $exc->getMessage(); $filename = $exc->getFile(); $linenum = $exc->getLine(); $debug_array = $exc->getTrace(); $back_trace = self::_errorBacktrace($debug_array); $err = self::_getOutputErrorMsg($errno, $errmsg, $filename, $linenum, $back_trace); BizSystem::logError($errno, "ExceptionHandler", $errmsg, null, $back_trace); if (defined('CLI') && CLI) { echo $err; } else { BizSystem::clientProxy()->showErrorMessage($err, true); } exit; }
/** * Выводит исключение * * @param object $oException Исключение */ function rx_exception($oException) { if (RUXON_DEBUG) { $title = 'Ruxon CMS: Исключение'; $content = 'Исключение: ' . $oException->getMessage() . '<br />' . 'В файле: ' . $oException->getFile() . '<br />' . 'В строке: ' . $oException->getLine() . '<br />' . '<pre>' . $oException->getTraceAsString() . '</pre>'; } else { $title = 'Ruxon CMS: Ошибка'; $content = $oException->getMessage(); } echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>' . $title . '</title> </head> <body> ' . $content . '</body></html>'; }
public function download() { if ($this->httpRequest->getExists('id')) { $iId = $this->httpRequest->get('id'); if (is_numeric($iId)) { $sFile = @$this->oGameModel->getFile($iId); $sPathFile = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'game/file/' . $sFile; if (!empty($sFile) && is_file($sPathFile)) { $sFileName = basename($sFile); $this->file->download($sPathFile, $sFileName); $this->oGameModel->setDownloadStat($iId); exit(0); } } } $this->sTitle = t('Wrong download ID specified!'); $this->_notFound(); $this->output(); }
/** * User exception handler * * @param object $exc hold error data * @return void * */ public static function exceptionHandler($exc) { $errno = $exc->getCode(); $errmsg = $exc->getMessage(); $filename = $exc->getFile(); $linenum = $exc->getLine(); $debug_array = $exc->getTrace(); $back_trace = self::_errorBacktrace($debug_array); $err = self::_getOutputErrorMsg($errno, $errmsg, $filename, $linenum, $back_trace); Openbizx::$app->getLog()->logError($errno, "ExceptionHandler", $errmsg, null, $back_trace); if (defined('CLI') && CLI || self::$errorMode == 'text') { echo $err; } else { Openbizx::$app->getClientProxy()->showErrorMessage($err, true); } if (!$exc->no_exit) { Openbizx::$app->getClientProxy()->printOutput(); exit; } }
/** * function called upon by global exception handler * * @param object $e exception thrown * @return void */ function handleBadgerException($e) { /** * Object containing global logging information * * @var object */ global $logger; echo "<b>"; echo getBadgerTranslation2('badgerException', 'Error'); echo "</b><br />"; echo getBadgerTranslation2($e->getBadgerErrorPage(), $e->getBadgerErrorId()); /** * Compiled error message * * @var string */ $loggedError = "ERROR: - ERROR Module: " . $e->getBadgerErrorPage() . ", ERROR Code: " . $e->getBadgerErrorId() . ", Error Description: " . getBadgerTranslation2($e->getBadgerErrorPage(), $e->getBadgerErrorId(), 'en') . " ON LINE " . $e->getLine() . " IN FILE " . $e->getFile() . " ADDITIONAL INFO " . $e->getAdditionalInfo(); // compile error message to be logged $logger->log($loggedError); //write to log file }
/** * 自定义异常处理 * * @author mrmsl <*****@*****.**> * @date 2012-09-12 13:30:32 * @lastmodify 2013-01-22 17:13:09 by mrmsl * * @param object $e 异常 * * @return void 无返回值 */ function exception_handler($e) { $message = $e->__toString(); error_handler(E_APP_EXCEPTION, $e->getMessage(), $e->getFile(), $e->getLine(), '__' . $e->getTraceAsString()); }
/** * Exception Handler * * Do not call this method directly. Function visibility is public because set_exception_handler does not allow for * protected method callbacks. * * @param object $exception The exception to be handled * @return bool */ public function _handleException($exception) { $result = false; if ($this->isEnabled(self::TYPE_EXCEPTION)) { //Handle \Error Exceptions in PHP7 if (class_exists('Error') && $exception instanceof \Error) { $message = $exception->getMessage(); $file = $exception->getFile(); $line = $exception->getLine(); $type = E_ERROR; //Set to E_ERROR by default if ($exception instanceof \DivisionByZeroError) { $type = E_WARNING; } if ($exception instanceof \AssertionError) { $type = E_WARNING; } if ($exception instanceof \ParseError) { $type = E_PARSE; } if ($exception instanceof \TypeError) { $type = E_RECOVERABLE_ERROR; } $result = $this->_handleError($type, $message, $file, $line, $exception); } else { $result = $this->handleException($exception); } } //Let the normal error flow continue return $result; }
/** * 将异常信息记录到$this->_error中 * * @param object $e * @return string */ private function soapFaultMsg($e) { $this->_error = $e->getMessage() . $e->getFile() . $e->getLine() . $e->getTraceAsString(); }
/** * Logs System Exceptions to DataBase * * @access public * @param object $exception * @return void */ public static function logError($exception) { try { $connection = new PDO('mysql:host=' . FOTOBAR_DB_HOST . ';dbname=' . FOTOBAR_DB_NAME, FOTOBAR_DB_USER, FOTOBAR_DB_AUTH); $sql = "INSERT INTO presswise_error_log (message, file, line, trace) VALUES (:message,:file,:line,:trace)"; $q = $connection->prepare($sql); $q->execute(array(':message' => $exception->getMessage(), ':file' => $exception->getFile(), ':line' => $exception->getLine(), ':trace' => $exception->getTraceAsString())); } catch (Exception $e) { var_dump($e); } }
/** * Error handler * * @param object $e */ public function exceptionHandler($e) { $message = "[<strong>Exception</strong>] \t" . $e->getFile() . ":" . $e->getLine() . " - " . $e->getMessage(); $this->_errors[] = $message; $this->_writeErrorLog($message); }
/** * Exception handler, catches exceptions that are not in a try/catch block * @param object $exception the exception object */ public static function exceptionHandler($exception) { $err = array('errno' => static::_msgType('exception'), 'errstr' => $exception->getMessage(), 'errfile' => $exception->getFile(), 'errline' => $exception->getLine()); static::_buildBuffer('log', '{errorHandler}', $err); }
/** * Logs System Exceptions to DataBase * * @param object $exception * @access public * @return void */ public static function logError($exception) { try { $connection = Netsuite_Db_Db::getInstance(); $sth = $connection->prepare(Netsuite_Db_Query::getQuery('LOG_ERROR')); if (!$sth) { throw new Exception(explode(',', $sth->errorInfo())); } $sth->execute(array(':message' => $exception->getMessage(), ':file' => $exception->getFile(), ':line' => $exception->getLine(), ':trace' => $exception->getTraceAsString())); } catch (Exception $e) { var_dump($e); } }
/** * Returns the statically rendered exception message * * @param integer $statusCode * @param object $exception \Exception or \Throwable * @return void */ protected function renderStatically($statusCode, $exception) { $statusMessage = Response::getStatusMessageByCode($statusCode); $exceptionHeader = ''; while (true) { $pathPosition = strpos($exception->getFile(), 'Packages/'); $filePathAndName = $pathPosition !== false ? substr($exception->getFile(), $pathPosition) : $exception->getFile(); $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : ''; $exceptionMessageParts = $this->splitExceptionMessage($exception->getMessage()); $exceptionHeader .= '<h2 class="ExceptionSubject">' . $exceptionCodeNumber . htmlspecialchars($exceptionMessageParts['subject']) . '</h2>'; if ($exceptionMessageParts['body'] !== '') { $exceptionHeader .= '<p class="ExceptionBody">' . nl2br(htmlspecialchars($exceptionMessageParts['body'])) . '</p>'; } $exceptionHeader .= ' <span class="ExceptionProperty">' . get_class($exception) . '</span> thrown in file<br /> <span class="ExceptionProperty">' . $filePathAndName . '</span> in line <span class="ExceptionProperty">' . $exception->getLine() . '</span>.<br />'; if ($exception instanceof FlowException) { $exceptionHeader .= '<span class="ExceptionProperty">Reference code: ' . $exception->getReferenceCode() . '</span><br />'; } if ($exception->getPrevious() === null) { break; } $exceptionHeader .= '<br /><div style="width: 100%; background-color: #515151; color: white; padding: 2px; margin: 0 0 6px 0;">Nested Exception</div>'; $exception = $exception->getPrevious(); } $backtraceCode = Debugger::getBacktraceCode($exception->getTrace()); echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <title>' . $statusCode . ' ' . $statusMessage . '</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style> .ExceptionSubject { margin: 0; padding: 0; font-size: 15px; color: #BE0027; } .ExceptionBody { padding: 10px; margin: 10px; color: black; background: #DDD; } .ExceptionProperty { color: #101010; } pre { margin: 0; font-size: 11px; color: #515151; background-color: #D0D0D0; padding-left: 30px; } </style> </head> <div style=" position: absolute; left: 10px; background-color: #B9B9B9; outline: 1px solid #515151; color: #515151; font-family: Arial, Helvetica, sans-serif; font-size: 12px; margin: 10px; padding: 0; "> <div style="width: 100%; background-color: #515151; color: white; padding: 2px; margin: 0 0 6px 0;">Uncaught Exception in Flow</div> <div style="width: 100%; padding: 2px; margin: 0 0 6px 0;"> ' . $exceptionHeader . ' <br /> ' . $backtraceCode . ' </div> </div> '; }
/** * Unload the test database and remove */ public function tearDown() { Flintstone::unload($this->dbName); @unlink($this->db->getFile()); clearstatcache(); }
/** * Prepare a response in case an error occurred. * * @param object $exception \Exception or \Throwable * @param Http\Response $response * @return void */ protected function prepareErrorResponse($exception, Http\Response $response) { $pathPosition = strpos($exception->getFile(), 'Packages/'); $filePathAndName = $pathPosition !== false ? substr($exception->getFile(), $pathPosition) : $exception->getFile(); $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : ''; $content = PHP_EOL . 'Uncaught Exception in Flow ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL; $content .= 'thrown in file ' . $filePathAndName . PHP_EOL; $content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL; $content .= Debugger::getBacktraceCode($exception->getTrace(), false, true) . PHP_EOL; if ($exception instanceof Exception) { $statusCode = $exception->getStatusCode(); } else { $statusCode = 500; } $response->setStatus($statusCode); $response->setContent($content); $response->setHeader('X-Flow-ExceptionCode', $exception->getCode()); $response->setHeader('X-Flow-ExceptionMessage', $exception->getMessage()); }
/** * output the error message. Requires the Exception object * * @param object $e */ private function error_string($e, $errors = null) { $errors = !empty($errors) ? $errors : pg_last_error($this->dbh); echo "<table cellpadding=\"4\" cellspacing=\"4\" width=\"98%\" \n\t\t\t\t\t style=\"border: 1px solid #990000;background-color:#eee;\n\t\t\t\t\t margin:10px;\">\n\t\t\t <tr>\n\t\t\t\t<td><b style=\"color:#990000;\"><u>db error:</u><b></td>\n\t\t\t\t<td>" . $e->getMessage() . "</td>\n\t\t\t </tr>\n\t\t\t <tr>\n\t\t\t \t<td><b style=\"color:#990000;\"><u>file:</u><b></td>\n\t\t\t\t<td>" . $e->getFile() . " [line " . $e->getLine() . "]</td>\n\t\t\t </tr>\n\t\t\t <tr>\n\t\t\t \t<td><b style=\"color:#990000;\"><u>db message:</u><b></td>\n\t\t\t\t<td>" . $errors . "</td>\n\t\t\t </tr>\n\t\t\t</table>"; }
/** * 将异常信息记录到$this->_error中 * * @param object $e * @return string */ private function soapFaultMsg($e) { $this->_error = $e->getMessage() . $e->getFile() . $e->getLine() . $e->getTraceAsString(); throw new SoapFault($e->getCode(), $e->getMessage()); }
/** * Normalises a backtrace. * * @param array|object $backtrace A backtrace array or an exception instance. * @return array A backtrace array. */ public static function normalise($backtrace) { if (!$backtrace instanceof Exception) { return $backtrace; } return array_merge([['function' => '[NA]', 'file' => $backtrace->getFile(), 'line' => $backtrace->getLine(), 'args' => []]], $backtrace->getTrace()); }
/** * adds an exception as error to the errors collection * this will end up in response.errors[] * * @note exception meta data (file, line, trace) is only shown when debug mode is on (@see base::$debug) * * @param object $exception extending \Exception * @param string $friendly_message optional, @see jsonapi\error->set_friendly_message() * @param string $about_link optional, @see jsonapi\error->set_about_link() */ public function add_exception($exception, $friendly_message = null, $about_link = null) { $error_message = $exception->getMessage(); $error_status = $exception->getCode(); $new_error = new error($error_message, $friendly_message, $about_link); if ($error_status) { $new_error->set_http_status($error_status); } // meta data if (base::$debug) { $file = $exception->getFile(); if ($file) { $file = str_replace($_SERVER['DOCUMENT_ROOT'] . '/', '', $file); $new_error->add_meta('file', $file); } $line = $exception->getLine(); if ($line) { $new_error->add_meta('line', $line); } $trace = $exception->getTrace(); if ($trace) { foreach ($trace as &$place) { if (!empty($place['file'])) { $place['file'] = str_replace($_SERVER['DOCUMENT_ROOT'] . '/', '', $place['file']); } } $new_error->add_meta('trace', $trace); } } $this->add_error_object($new_error); $previous_exception = $exception->getPrevious(); if ($previous_exception) { $this->add_exception($previous_exception); } }
/** * Log API exceptions and print error to screen if required * * @param object $e * @param string $tterrorstr * @param boolean $toscreen */ public static function handle_exceptions($e, $tterrorstr = "", $toscreen = true, $embedded = false) { $errorstr = ""; if (!empty($tterrorstr)) { $errorstr = get_string($tterrorstr, 'turnitintooltwo') . "<br/><br/>"; if ($embedded == true) { $errorstr .= get_string('tii_submission_failure', 'turnitintooltwo') . "<br/><br/>"; } } if (is_callable(array($e, 'getFaultCode'))) { $errorstr .= get_string('faultcode', 'turnitintooltwo') . ": " . $e->getFaultCode() . " | "; } if (is_callable(array($e, 'getFile'))) { $errorstr .= get_string('file') . ": " . $e->getFile() . " | "; } if (is_callable(array($e, 'getLine'))) { $errorstr .= get_string('line', 'turnitintooltwo') . ": " . $e->getLine() . " | "; } if (is_callable(array($e, 'getMessage'))) { $errorstr .= get_string('message', 'turnitintooltwo') . ": " . $e->getMessage() . " | "; } if (is_callable(array($e, 'getCode'))) { $errorstr .= get_string('code', 'turnitintooltwo') . ": " . $e->getCode(); } turnitintooltwo_activitylog($errorstr, "API_ERROR"); if ($toscreen) { turnitintooltwo_print_error($errorstr, null); } else { if ($embedded) { return $errorstr; } } }
/** * Creates a name for the file being uploaded. * * @param object $obj The object the upload is attached to. * @param string $field The name of the uploadable field to generate a name for. * @return string The file name. */ function name($obj, $field) { $file = $obj->getFile(); $extension = $file->guessExtension(); return uniqid('', true) . '.' . $extension; }
/** * 自定义异常处理 * * @author mrmsl <*****@*****.**> * @date 2012-09-12 13:30:32 * @lastmodify 2013-01-22 17:13:09 by mrmsl * * @param object $e 异常 * * @return void 无返回值 */ function exception_handler($e) { $message = $e->__toString(); //入库 sys_config('sys_log_systemerror') && D('Log')->addLog(nl2br($message), LOG_TYPE_SYSTEM_ERROR); error_handler(E_APP_EXCEPTION, $e->getMessage(), $e->getFile(), $e->getLine(), '__' . $e->getTraceAsString()); }
/** * Carrega a página de erro de acordo com as configurações e mata a execução * @param object $error instância de Exception * @return void */ private function loadError($error) { Error::render($error->getCode(), $error->getMessage(), $error->getFile(), $error->getLine(), $error->getTraceAsString(), method_exists($error, 'getDetails') ? $error->getDetails() : ''); }