예제 #1
0
 /**
  * Render an error page.
  */
 public function render()
 {
     $error = $this->getError();
     $messageBox = new Template('sledgehammer/mvc/templates/httperror.php', $error);
     $messageBox->render();
     foreach ($this->options as $option => $value) {
         switch ((string) $option) {
             case 'notice':
             case 'warning':
                 $function = $option;
                 if (is_array($value)) {
                     call_user_func_array($function, $value);
                 } else {
                     call_user_func($function, $value);
                 }
                 break;
             case 'exception':
                 \Sledgehammer\report_exception($value);
                 break;
             default:
                 \Sledgehammer\notice('Unknown option: "' . $option . '"', array('value' => $value));
                 break;
         }
     }
 }
예제 #2
0
 public function __toString()
 {
     try {
         return \Sledgehammer\component_to_string($this);
     } catch (Exception $e) {
         \Sledgehammer\report_exception($e);
         return '';
     }
 }
예제 #3
0
 private function assertEqualTokenizer($filename)
 {
     $content = file_get_contents($filename);
     //Framework::$autoLoader->getFilename('Sledgehammer\GoogleAnalytics');
     try {
         $tokenIterator = new PhpTokenizer($content);
         $mergedTokens = '';
         $tokens = [];
         foreach ($tokenIterator as $token) {
             $mergedTokens .= $token[1];
             $tokens[] = $token;
         }
         $this->assertSame($content, $mergedTokens, 'Input should match all tokens combined (file: "' . $filename . '")');
     } catch (Exception $e) {
         \Sledgehammer\report_exception($e);
         ob_flush();
         $this->fail($e->getMessage());
     }
 }
예제 #4
0
파일: Dump.php 프로젝트: sledgehammer/core
 public function __toString()
 {
     try {
         ob_start();
         $this->render();
         return ob_get_clean();
     } catch (Exception $e) {
         \Sledgehammer\report_exception($e);
         return '';
     }
 }
예제 #5
0
 /**
  * Write session-data for the given $id.
  *
  * @param string $id
  * @param string $gegevens
  *
  * @return bool
  */
 public function write($id, $gegevens)
 {
     try {
         $db = Connection::instance($this->dbLink);
         $result = $db->query('REPLACE INTO ' . $db->quoteIdentifier($this->table) . ' VALUES (' . $db->quote($id) . ', "' . time() . '", ' . $db->quote($gegevens) . ')');
         if ($result) {
             return true;
         }
     } catch (\Exception $e) {
         \Sledgehammer\report_exception($e);
     }
     return false;
 }
예제 #6
0
파일: Sql.php 프로젝트: sledgehammer/core
 /**
  * Allow the SQL object to be used as string.
  *
  * @return string
  */
 public function __toString()
 {
     try {
         return $this->compose();
     } catch (Exception $e) {
         // __toString must not throw an exception
         \Sledgehammer\report_exception($e);
         return '';
     } catch (\Throwable $e) {
         \Sledgehammer\report_exception($e);
         return '';
     }
 }
예제 #7
0
파일: Json.php 프로젝트: sledgehammer/core
 /**
  * Reports the error/exception to the ErrorHandler and returns the error as Json object.
  * The javascript client should detect and report the error to the user:
  *   if (result.success !== true) { alert(result.error); }.
  *
  * @param string|Exception $error The error message or Exception
  * @param int              $http  The HTTP status code (defaults to 400 Bad Request)
  *
  * @return Json
  */
 public static function error($error, $http = 400)
 {
     if (headers_sent() === false && DebugR::isEnabled()) {
         ErrorHandler::instance()->html = false;
     }
     if ($error instanceof Exception) {
         \Sledgehammer\report_exception($error);
         $error = $error->getMessage();
     } else {
         \Sledgehammer\warning($error);
     }
     return new self(array('success' => false, 'error' => $error), array('http' => array('Status' => $http . ' ' . Framework::$statusCodes[$http], 'Content-Type' => ErrorHandler::instance()->html ? 'text/html;  charset=utf-8' : 'application/json')));
 }
예제 #8
0
파일: Curl.php 프로젝트: sledgehammer/core
 /**
  * Returns the response body.
  *
  * @return string
  */
 public function __toString()
 {
     try {
         return $this->getContent();
     } catch (Exception $e) {
         \Sledgehammer\report_exception($e);
         return '';
     }
 }
예제 #9
0
 /**
  * Report an exception.
  *
  * @param Exception $exception
  */
 function report_exception($exception)
 {
     Sledgehammer\report_exception($exception);
 }