Beispiel #1
0
 /**
  * Gibt das JSON für den String zurück
  *
  * asserted dass das dekodieren auch klappt
  * @param $array macht alle objekte im json zu arrays! (huh)
  * @return object|array
  */
 public function json($json, $array = FALSE, $canBeEmpty = FALSE)
 {
     $data = json_decode($json, $array);
     $json_errors = array(JSON_ERROR_NONE => 'Es ist kein Fehler zuvor aufgetreten, aber der Array ist leer. Es kann mit dem 3ten Parameter TRUE umgangen werden, dass der Array überprüft wird', JSON_ERROR_DEPTH => 'Die maximale Stacktiefe wurde erreicht', JSON_ERROR_CTRL_CHAR => 'Steuerzeichenfehler, möglicherweise fehlerhaft kodiert', JSON_ERROR_SYNTAX => 'Syntax Error');
     if ($canBeEmpty && (is_array($data) || is_object($data))) {
         return $data;
     }
     $this->testCase->assertNotEmpty($data, "JSON Error: " . $json_errors[json_last_error()] . " für JSON-String: '" . \Webforge\Common\String::cut($json, 100, '...'));
     return $data;
 }
Beispiel #2
0
 public function errorToString($error)
 {
     $context = array_key_exists($error->line - 1, $this->rawLines) ? $this->rawLines[$error->line - 1] : '[no context avaible]';
     $ret = NULL;
     switch ($error->level) {
         case LIBXML_ERR_WARNING:
             $ret .= "Libxml-Warning {$error->code}: ";
             break;
         case LIBXML_ERR_ERROR:
             $ret .= "Libxml-Error {$error->code}: ";
             break;
         case LIBXML_ERR_FATAL:
             $ret .= "Libxml-Fatal Error {$error->code}: ";
             break;
     }
     $ret .= trim($error->message) . "\n  near: '" . \Webforge\Common\String::cut($context, 140, "'...") . "\n  Line: {$error->line}" . "\n  Column: {$error->column}";
     return $ret;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function startQuery($sql, array $params = null, array $types = null)
 {
     if ($params != NULL) {
         foreach ($params as $p) {
             try {
                 if (is_array($p)) {
                     $p = Helper::implodeIdentifiers($p);
                 }
             } catch (\Exception $e) {
                 $p = '[unconvertible array]';
             }
             if (is_string($p)) {
                 $p = "'" . \Webforge\Common\String::cut($p, 50, '...') . "'";
             }
             if ($p instanceof \DateTime) {
                 $p = $p->format('YDM-H:I');
             }
             $sql = preg_replace('/\\?/', (string) $p, $sql, 1);
             // ersetze das erste ? mit dem parameter
         }
     }
     print $sql . PHP_EOL;
     flush();
 }