/** * Output pretty-printed arrays / objects. * * @see \Dumper::dump * * @param mixed $var * @return string */ public function printDump($var) { if ($this->safe) { return '?'; } if ($this->app['config']->get('general/debug')) { return \Dumper::dump($var, DUMPER_CAPTURE); } else { return ''; } }
public function dump($subject, $nestLevel = 0) { $elements = []; foreach (get_object_vars($subject) as $key => $value) { $elements[] = sprintf("'%s' => %s", $key, $this->masterDumper->dump($value, $nestLevel)); } $methods = get_class_methods($subject); $approvedMethods = array_filter($methods, function ($method) use($subject) { if (preg_match("/^(get|has|is)[A-Z]/", $method) > 0) { $reflection = new \ReflectionMethod(get_class($subject), $method); if ($reflection->getNumberOfParameters() === 0) { return true; } return false; } }); foreach ($approvedMethods as $method) { $key = lcfirst(preg_replace("/^(get|has|is)/", '', $method)); $value = call_user_func([$subject, $method]); // $value = $method; $elements[] = sprintf("'%s' => %s", $key, $this->masterDumper->dump($value, $nestLevel)); } return "[\n\t" . implode(",\n\t", preg_replace("/\n/", "\n\t", $elements)) . "\n],\n"; }
public function testDumpSubsections() { $data = array('main' => array('explore' => true, 'sub' => array('sub' => array('value' => 5)))); $dumper = new Dumper(); $result = $dumper->dump($data); $expected = <<<EOT [main] explore=true [main.sub] [main.sub.sub] value=5 EOT; $this->assertEquals($expected, $result); }
/** * * @param mixed $source DataURI source * @param boolean $strict Use strict mode (length output) * @param string $mime the mime type * @param array $parameters Extra parameters, see rfc * @return null */ public function dataUri($source, $strict = true, $mime = null, $parameters = array()) { $data = null; try { switch (true) { case is_resource($source): $data = $this->getDataFromRessource($source, $strict, $mime, $parameters); break; case is_scalar($source): $data = $this->getDataFromScalar($source, $strict, $mime, $parameters); break; default: trigger_error("Tried to convert an unsupported source format", E_USER_WARNING); break; } } catch (Exception\Exception $e) { trigger_error(sprintf("Error while building DataUri : %s", $e->getMessage()), E_USER_WARNING); } if ($data) { return Dumper::dump($data); } return null; }
/** * Dumps a PHP array to a YAML string. * * The dump method, when supplied with an array, will do its best * to convert the array into friendly YAML. * * @param array $array PHP array * @param integer $inline The level where you switch to inline YAML * * @return string A YAML string representing the original PHP array */ public static function dump($array, $inline = 2) { $yaml = new Dumper(); return $yaml->dump($array, $inline); }
/** * Dump containers. * * @param array $containers An array of containers. * * @api */ public function dumpContainers(array $containers) { // output foreach ($containers as $container) { foreach ($container->getDefinitions() as $name => $definition) { $output = $definition->getOutput($name); $dir = $output->getDir(); $file = $dir . DIRECTORY_SEPARATOR . str_replace('\\', '/', $definition->getClass()) . '.php'; $path = dirname($file); if (!file_exists($path) && false === @mkdir($path, 0777, true)) { throw new \RuntimeException(sprintf('Unable to create the %s directory.', $path)); } if (!is_writable($path)) { throw new \RuntimeException(sprintf('Unable to write in the %s directory.', $path)); } if (!file_exists($file) || $output->getOverride()) { $dumper = new Dumper($definition); $content = $dumper->dump(); $tmpFile = tempnam(dirname($file), basename($file)); if (false === @file_put_contents($tmpFile, $content) || !@rename($tmpFile, $file)) { throw new \RuntimeException(sprintf('Failed to write the file "%s".', $file)); } @chmod($file, 0666 & ~umask()); } } } }
/** * Output pretty-printed arrays / objects. * * @see \Dumper::dump * * @param mixed $var * @return string */ public function printDump($var) { return \Dumper::dump($var, DUMPER_CAPTURE); }
$tmpname1 = tempnam('', ''); $tmpname2 = tempnam('', ''); $file_name1 = 'files/' . str_pad($i * $delta, 8, '0', STR_PAD_LEFT) . '.json.gz'; $file_name2 = 'files/bussiness-' . str_pad($i * $delta, 8, '0', STR_PAD_LEFT) . '.json.gz'; $fp[1] = $fp[3] = gzopen($tmpname1, 'w'); $fp[2] = gzopen($tmpname2, 'w'); $unit_id = null; $unit = new StdClass(); foreach (UnitData::search("`id` >= {$start} AND `id` <= {$end}")->order("`id`, `column_id`")->volumemode(10000) as $unit_data) { if (!is_null($unit_id) and $unit_data->id != $unit_id) { fwrite($fp[$this->getType($unit_id)], str_pad($unit_id, 8, '0', STR_PAD_LEFT) . ',' . json_encode($unit, JSON_UNESCAPED_UNICODE) . "\n"); $unit = new StdClass(); } $unit_id = $unit_data->id; $unit->{$columns[$unit_data->column_id]} = json_decode($unit_data->value); } if (!is_null($unit_id)) { fwrite($fp[$this->getType($unit_id)], str_pad($unit_id, 8, '0', STR_PAD_LEFT) . ',' . json_encode($unit, JSON_UNESCAPED_UNICODE) . "\n"); } fclose($fp[1]); fclose($fp[2]); DropboxLib::putFile($tmpname1, $file_name1); DropboxLib::putFile($tmpname2, $file_name2); unlink($tmpname1); unlink($tmpname2); } } } $dumper = new Dumper(); $dumper->dump();
<?php require '../../class.dumper.php'; class A { public $b; public $c; } $x = new A(); $x->b = new A(); $x->b->b = new A(); $x->b->c = new A(); $x->b->c->b = new A(); Dumper::dump($x);
/** * Dump information about a variable * * @param mixed $data,... * @access public * @static */ public static function dump($data, $capture = false) { // If we're capturing call dump() with just data and capture the output if ($capture === DUMPER_CAPTURE) { ob_start(); Dumper::dump($data); $str = ob_get_clean(); return $str; } $clearObjectRecursionProtection = false; if (self::$objectRecursionProtection === NULL) { self::$objectRecursionProtection = array(); $clearObjectRecursionProtection = true; } // disabled if (!Dumper::_debug()) { return false; } // more arguments if (func_num_args() > 1) { $_ = func_get_args(); foreach ($_ as $d) { Dumper::dump($d); } return; } // find caller $_ = debug_backtrace(); while ($d = array_pop($_)) { $callback = self::$lineNumberTestCallback; $function = strToLower($d['function']); if (in_array($function, array("krumo", "k", "kd")) || strToLower(@$d['class']) == 'krumo' || is_callable($callback) && $callback($d)) { break; } } $showVersion = Dumper::_config('display', 'show_version', TRUE); $showCallInfo = Dumper::_config('display', 'show_call_info', TRUE); $krumoUrl = 'https://github.com/oodle/krumo'; ////////////////////// // Start HTML header// ////////////////////// print "<div class=\"dumper-root\">\n"; print "\t<ul class=\"dumper-node dumper-first\">\n"; // The actual item itself print Dumper::_dump($data); if ($showVersion || $showCallInfo) { print "\t\t<li class=\"dumper-footnote\" onDblClick=\"toggle_expand_all();\">\n"; if ($showCallInfo && isset($d['file']) && $d['file']) { print "<span class=\"dumper-call\" style=\"white-space:nowrap;\">"; print "Called from <strong><code>" . $d['file'] . "</code></strong>, "; print "line <strong><code>" . $d['line'] . "</code></strong></span>"; } if ($showVersion) { $version = Dumper::version(); print "<span class=\"dumper-version\" style=\"white-space:nowrap;\">\n"; print "<strong class=\"dumper-version-number\">Krumo version {$version}</strong> | <a href=\"{$krumoUrl}\" target=\"_blank\">{$krumoUrl}</a>\n"; print "</span>\n"; } print "</li>"; } print "</ul></div>\n"; print "<!-- Dumper - HTML -->\n\n"; // Output the CSS and JavaScript AFTER the HTML Dumper::_css(); //////////////////// // End HTML header// //////////////////// // flee the hive $_recursion_marker = Dumper::_marker(); if ($hive =& Dumper::_hive($dummy)) { foreach ($hive as $i => $bee) { if (is_object($bee)) { if (($hash = spl_object_hash($bee)) && isset(self::$objectRecursionProtection[$hash])) { unset(self::$objectRecursionProtection[$hash]); } } elseif (isset($hive[$i]->{$_recursion_marker})) { unset($hive[$i][$_recursion_marker]); } } } if ($clearObjectRecursionProtection) { self::$objectRecursionProtection = NULL; } // End of dump() }
/** * Get the next number from a sequence * * @return int */ private function getSequence($formconfig, $form, $formname, $column) { $sequence = null; // Attempt get the next sequence from a table, if specified.. if (!empty($formconfig['insert_into_table'])) { try { $query = sprintf("SELECT MAX(%s) as max FROM %s", $column, $formconfig['insert_into_table']); $sequence = $this->app['db']->executeQuery($query)->fetchColumn(); } catch (\Doctrine\DBAL\DBALException $e) { // Oops. User will get a warning on the dashboard about tables that need to be repaired. $this->app['log']->add("SimpleForms could not fetch next sequence number from table" . $formconfig['insert_into_table'] . ' - check if the table exists.', 3); echo "Couldn't fetch next sequence number from table " . $formconfig['insert_into_table'] . "."; } } $sequence++; if ($formconfig['debugmode'] == true) { \Dumper::dump('Get sequence for ' . $formname . ' column: ' . $column . ' - ' . $sequence); } return $sequence; }
<?php require '../../class.dumper.php'; $obj = (object) array('a' => array('b' => array('c' => array('d' => array('e' => null))))); Dumper::dump($obj);