Beispiel #1
0
 /**
  * Helper function that logs the actual message. If it can't log a message to the
  * database we trigger an error in the apache log.
  *
  * @static
  * @param $type
  * @param $message
  * @param $detail
  * @throws Exception
  */
 protected static function writeLog($type, $message, $detail)
 {
     $db = call_user_func(static::$dbObjectCallback);
     if (!$db instanceof DB_Base) {
         throw new Exception("The database object returned by the dbObjectCallback must return an instance of the DB class");
     }
     //get caller
     $source = static::getCaller();
     $data = array('type' => $type, 'scriptName' => $_SERVER['SCRIPT_NAME'], 'uri' => $_SERVER['REQUEST_URI'], 'message' => $message, 'serverHost' => $_SERVER['SERVER_NAME'], 'logSource' => $source, 'logCreated' => date("Y-m-d h:i:s"));
     //if it's an object or an array make sure we dump it so we get everything output
     if (is_object($detail) || is_array($detail)) {
         $detail = Dump::out($detail)->returned();
     }
     if (null !== $detail) {
         $data['messageDetail'] = $detail;
     }
     $result = $db->insert(static::$tableName, $data);
     if (false == $result) {
         trigger_error("Unable to write to the log table.", E_WARNING);
     }
 }
Beispiel #2
0
 /**
  * @dataProvider dataFunctionalStringFormatting
  * @param string $in Input string to format
  * @param string $out Expected result as the secondary format of the string
  */
 public function testFunctionalStringFormatting($in, $out)
 {
     $html = Dump::out($in)->asHtml()->returned();
     $result = preg_match('~\\<span style\\=\\"display\\: none\\"\\>(.*)\\<\\/span\\>~ms', $html, $matches);
     $this->assertTrue((bool) $result, 'Did not find match in HTML: ' . $html);
     // Reformat the result back into text
     $string = $matches[1];
     $string = str_replace("&nbsp; &nbsp; &nbsp; &nbsp; ", "\t", $string);
     $string = str_replace("<br />\n", "\n", $string);
     $string = html_entity_decode($string);
     $this->assertEquals($out, $string, 'Specially formatted string does not match');
 }