/** * Constructor... * * @param String $query The query that caused the error * @param String $message The error message * @param Integer $code The error code * @param Mixed $link The database Link associated with this error */ public function __construct($message = NULL, $code = 0, $link = null) { parent::__construct($message, $code); if ($link instanceof \r8\iface\DB\Identified) { $this->addData('Link', $link->getIdentifier()); } else { $this->addData('Link', \r8\getDump($link)); } }
/** * Formats an array as a JSON object * * @param Array $data * @return String */ private function formatArray(array $data) { $result = ""; foreach ($data as $key => $value) { if (!\r8\isBasic($value)) { $value = \r8\getDump($value); } $result .= '"' . $key . '":' . json_encode($value) . ", "; } return rtrim($result, ", "); }
/** * Formats an array as a key/value HTML pairing * * @param Array $data * @return String */ private function formatArray(array $data) { $result = ""; foreach ($data as $key => $value) { if (!\r8\isBasic($value)) { $value = \r8\getDump($value); } $result .= " <tr>\n" . " <th style='padding: 4px 8px; font-weight: normal; font-style: italic; text-align: right;'>" . $key . "</th>\n" . " <td style='padding: 4px 8px;'>" . htmlspecialchars($value) . "</td>\n" . " </tr>\n"; } return $result; }
/** * A helper function for building a node, ensuring a proper value was returned, * and then importing it into the document * * @param \r8\iface\XMLBuilder $builder * @param \DOMDocument $doc The document being built * @return DOMNode */ public static function buildNode(\r8\iface\XMLBuilder $builder, \DOMDocument $doc) { $built = $builder->buildNode($doc); if (!$built instanceof \DOMNode) { $err = new \r8\Exception\Interaction("XMLBuilder did not return a DOMNode object"); $err->addData("Document", \r8\getDump($doc)); $err->addData("Built Node", \r8\getDump($built)); throw $err; } // Ensure the built node is a member of the document return \r8\XMLBuilder::importNode($doc, $built); }
public function testGetDump() { $this->assertEquals("bool(TRUE)", \r8\getDump(TRUE)); $this->assertEquals("bool(FALSE)", \r8\getDump(FALSE)); $this->assertEquals("null()", \r8\getDump(null)); $this->assertEquals("int(1)", \r8\getDump(1)); $this->assertEquals("float(10.5)", \r8\getDump(10.5)); $this->assertEquals("string('some string')", \r8\getDump("some string")); $this->assertEquals("string('some string that is goi'...'after fifty characters')", \r8\getDump("some string that is going to be trimmed after fifty characters")); $this->assertEquals("string('some\\nstring\\twith\\rbreaks')", \r8\getDump("some\nstring\twith\rbreaks")); $this->assertEquals("array(0)", \r8\getDump(array())); $this->assertEquals("array(1)(int(0) => int(5))", \r8\getDump(array(5))); $this->assertEquals("array(2)(int(0) => string('string'), int(20) => float(1.5))", \r8\getDump(array("string", 20 => 1.5))); $this->assertEquals("array(5)(int(0) => int(1), int(1) => int(2),...)", \r8\getDump(array(1, 2, 3, 4, 20))); $this->assertEquals("array(1)(int(0) => array(2))", \r8\getDump(array(array(5, 6)))); $this->assertEquals("object(Exception)", \r8\getDump(new Exception())); $this->assertEquals("resource(stream)", \r8\getDump(fopen(__FILE__, "r"))); }
/** * Constructor... * * @param Integer $offset The offset at which to start iteration * @param \Traversable $inner The iterator being wrapped */ public function __construct($offset, \Traversable $inner) { $this->inner = $inner; $offset = (int) $offset; // If we can, be intelligent about the offset if ($inner instanceof \Countable) { try { $offset = \r8\num\offsetWrap($inner->count(), $offset, \r8\num\OFFSET_NONE); } catch (\r8\Exception\Index $err) { $offset = NULL; } } else { if ($offset < 0) { $err = new \r8\Exception\Index($offset, "Iterator Offset", "Negative offsets are only supported if Iterator implements the Countable interface"); $err->addData("Iterator", \r8\getDump($inner)); throw $err; } } $this->offset = $offset; }
/** * Formats an error as a string * * @param \r8\iface\Error $error The error to format * @return String Returns the formatted error */ public function format(\r8\iface\Error $error) { $formatter = new \r8\Backtrace\Formatter(new \r8\Backtrace\Formatter\Text()); $result = "\n" . "PHP Error Encountered!\n"; foreach ($this->toArray($error) as $key => $value) { $result .= $key . ": " . $value . "\n"; } $details = $error->getDetails(); if (!empty($details)) { $result .= "Details:\n"; foreach ($details as $key => $value) { if (!\r8\isBasic($value)) { $value = \r8\getDump($value); } $result .= " " . $key . ": " . $value . "\n"; } } $result .= "Backtrace:\n" . " " . str_replace("\n", "\n ", $formatter->format($error->getBacktrace())) . "\n\n"; return $result; }
/** * Constructor * * @param String $value The value of the data that caused the error * @param String $label The name of the data * @param String $message The error message * @param Integer $code The error code */ public function __construct($value, $label = NULL, $message = NULL, $code = 0) { parent::__construct($message, $code); $this->addData("Index Label", (string) $label); $this->addData("Value", \r8\getDump($value)); }
/** * Dumps the ending call to a function * * @param String $method The method that was called * @param Mixed $result The result from the method call * @return NULL */ private function dumpEnd($method, $result) { printf("%s::%-8s End %s\n", spl_object_hash($this), $method, \r8\getDump($result)); }
/** * Returns the data list for the current instance * * @return Array */ public function getData() { return array("Arg Offset" => $this->getArgOffset(), "Arg Value" => \r8\getDump($this->getArgData())) + parent::getData(); }
/** * Runs a query and returns a specific field from a row * * If no row is specified, the first row will be used * * @param String $field The field to return * @param String $query The query to execute * @param Integer $row The row of a multi-result set to pull the field from * @return Mixed Returns the value of the field, or NULL if no results * were returned */ public function getField($field, $query, $row = 0) { $field = (string) $field; if (\r8\isEmpty($field)) { throw new \r8\Exception\Argument(0, "Field", "Must not be empty"); } $result = $this->getRow($query, $row); if (!is_array($result) && !$result instanceof \ArrayAccess) { $err = new \r8\Exception\Interaction("Row was not an array or accessable as an array"); $err->addData("Query", $query); $err->addData("Returned Row", \r8\getDump($result)); throw $err; } if (!isset($result[$field])) { $err = new \r8\Exception\Argument(0, "Field", "Field does not exist in row"); $err->addData("Query", $query); $err->addData("Returned Row", \r8\getDump($result)); throw $err; } return $result[$field]; }
/** * Constructor * * @param String $value The value of the data that caused the error * @param String $label The name of the data * @param String $message The error message * @param Integer $code The error code */ public function __construct($value, $label = NULL, $message = NULL, $code = 0) { parent::__construct($message, $code); $label = (string) $label; $this->addData(\r8\isEmpty($label) ? "Value" : $label, \r8\getDump($value)); }