本文整理汇总了PHP中Dumper类的典型用法代码示例。如果您正苦于以下问题:PHP Dumper类的具体用法?PHP Dumper怎么用?PHP Dumper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dumper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ocd_restore
function ocd_restore()
{
$file = $this->GetGP("file");
$appRoot = $this->sitePath;
$dumper = new Dumper(DbName, $appRoot . "data/backups/");
$file_name = $dumper->restore($file);
if ($file_name != "") {
$this->Redirect($this->pageUrl . "?ec=restore_ok&fn={$file_name}");
} else {
$this->Redirect($this->pageUrl . "?ec=restore_error");
}
}
示例2: testDumpSubsections
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);
}
示例3: render
/**
* Renders debug bar.
* @return void
*/
public function render()
{
$useSession = $this->dispatched && session_status() === PHP_SESSION_ACTIVE;
$redirectQueue =& $_SESSION['_tracy']['redirect'];
if (!Helpers::isHtmlMode() && !Helpers::isAjax()) {
return;
} elseif (Helpers::isAjax()) {
$rows[] = (object) ['type' => 'ajax', 'panels' => $this->renderPanels('-ajax')];
$dumps = Dumper::fetchLiveData();
$contentId = $useSession ? $_SERVER['HTTP_X_TRACY_AJAX'] . '-ajax' : NULL;
} elseif (preg_match('#^Location:#im', implode("\n", headers_list()))) {
// redirect
$redirectQueue = array_slice((array) $redirectQueue, -10);
Dumper::fetchLiveData();
Dumper::$livePrefix = count($redirectQueue) . 'p';
$redirectQueue[] = ['panels' => $this->renderPanels('-r' . count($redirectQueue)), 'dumps' => Dumper::fetchLiveData()];
return;
} else {
$rows[] = (object) ['type' => 'main', 'panels' => $this->renderPanels()];
$dumps = Dumper::fetchLiveData();
foreach (array_reverse((array) $redirectQueue) as $info) {
$rows[] = (object) ['type' => 'redirect', 'panels' => $info['panels']];
$dumps += $info['dumps'];
}
$redirectQueue = NULL;
$contentId = $useSession ? substr(md5(uniqid('', TRUE)), 0, 10) : NULL;
}
ob_start(function () {
});
require __DIR__ . '/assets/Bar/panels.phtml';
require __DIR__ . '/assets/Bar/bar.phtml';
$content = Helpers::fixEncoding(ob_get_clean());
if ($contentId) {
$queue =& $_SESSION['_tracy']['bar'];
$queue = array_slice(array_filter((array) $queue), -5, NULL, TRUE);
$queue[$contentId] = ['content' => $content, 'dumps' => $dumps];
}
if (Helpers::isHtmlMode()) {
$stopXdebug = extension_loaded('xdebug') ? ['XDEBUG_SESSION_STOP' => 1, 'XDEBUG_PROFILE' => 0, 'XDEBUG_TRACE' => 0] : [];
$path = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI'])[0] : '/';
$lpath = strtolower($path);
$script = isset($_SERVER['SCRIPT_NAME']) ? strtolower($_SERVER['SCRIPT_NAME']) : '';
if ($lpath !== $script) {
$max = min(strlen($lpath), strlen($script));
for ($i = 0; $i < $max && $lpath[$i] === $script[$i]; $i++) {
}
$path = $i ? substr($path, 0, strrpos($path, '/', $i - strlen($path) - 1) + 1) : '/';
$cookiePath = session_get_cookie_params()['path'];
if (substr($cookiePath, 0, strlen($path)) === $path) {
$path = rtrim($cookiePath, '/') . '/';
}
}
require __DIR__ . '/assets/Bar/loader.phtml';
}
}
示例4: printBacktrace
/**
* Output pretty-printed backtrace.
*
* @see \Dumper::backtrace
*
* @param mixed $var
* @return string
*/
public function printBacktrace($depth = 15)
{
if ($this->safe) {
return null;
}
if ($this->app['config']->get('general/debug')) {
return \Dumper::backtrace($depth, true);
} else {
return '';
}
}
示例5: renderHtml
private function renderHtml()
{
$res = '<style>code, pre {white-space:nowrap} a {text-decoration:none} pre {color:gray;display:inline} big {color:red}</style><code>';
foreach ($this->list as $item) {
$stack = [];
foreach (array_slice($item[3], 1) as $t) {
$t += ['class' => '', 'type' => '', 'function' => ''];
$stack[] = "{$t['class']}{$t['type']}{$t['function']}()" . (isset($t['file'], $t['line']) ? ' in ' . basename($t['file']) . ":{$t['line']}" : '');
}
$res .= Helpers::editorLink($item[0], $item[1]) . ' ' . '<span title="' . htmlspecialchars(implode("\n", $stack), ENT_IGNORE | ENT_QUOTES, 'UTF-8') . '">' . str_replace(self::BOM, '<big>BOM</big>', Dumper::toHtml($item[2])) . "</span><br>\n";
}
return $res . '</code>';
}
示例6: formatMessage
/**
* @param string|\Exception|\Throwable
* @return string
*/
protected function formatMessage($message)
{
if ($message instanceof \Exception || $message instanceof \Throwable) {
while ($message) {
$tmp[] = ($message instanceof \ErrorException ? 'Fatal error: ' . $message->getMessage() : get_class($message) . ': ' . $message->getMessage()) . ' in ' . $message->getFile() . ':' . $message->getLine();
$message = $message->getPrevious();
}
$message = implode($tmp, "\ncaused by ");
} elseif (!is_string($message)) {
$message = Dumper::toText($message);
}
return trim($message);
}
示例7: formatMessage
/**
* @param string|\Exception|\Throwable
* @return string
*/
protected function formatMessage($message)
{
if ($message instanceof \Exception || $message instanceof \Throwable) {
while ($message) {
$tmp[] = ($message instanceof \ErrorException ? Helpers::errorTypeToString($message->getSeverity()) . ': ' . $message->getMessage() : Helpers::getClass($message) . ': ' . $message->getMessage() . ($message->getCode() ? ' #' . $message->getCode() : '')) . ' in ' . $message->getFile() . ':' . $message->getLine();
$message = $message->getPrevious();
}
$message = implode("\ncaused by ", $tmp);
} elseif (!is_string($message)) {
$message = Dumper::toText($message);
}
return trim($message);
}
示例8: run
/**
* Runs the test case.
* @return void
*/
public function run($method = NULL)
{
$rc = new \ReflectionClass($this);
$methods = $method ? array($rc->getMethod($method)) : $rc->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
if (!preg_match('#^test[A-Z]#', $method->getName())) {
continue;
}
$data = array();
$info = Helpers::parseDocComment($method->getDocComment()) + array('dataprovider' => NULL, 'throws' => NULL);
if ($info['throws'] === '') {
throw new TestCaseException("Missing class name in @throws annotation for {$method->getName()}().");
} elseif (is_array($info['throws'])) {
throw new TestCaseException("Annotation @throws for {$method->getName()}() can be specified only once.");
} else {
$throws = preg_split('#\\s+#', $info['throws'], 2) + array(NULL, NULL);
}
foreach ((array) $info['dataprovider'] as $provider) {
$res = $this->getData($provider);
if (!is_array($res)) {
throw new TestCaseException("Data provider {$provider}() doesn't return array.");
}
$data = array_merge($data, $res);
}
if (!$info['dataprovider']) {
if ($method->getNumberOfRequiredParameters()) {
throw new TestCaseException("Method {$method->getName()}() has arguments, but @dataProvider is missing.");
}
$data[] = array();
}
foreach ($data as $args) {
try {
if ($info['throws']) {
$tmp = $this;
$e = Assert::error(function () use($tmp, $method, $args) {
$tmp->runTest($method->getName(), $args);
}, $throws[0], $throws[1]);
if ($e instanceof AssertException) {
throw $e;
}
} else {
$this->runTest($method->getName(), $args);
}
} catch (AssertException $e) {
$e->message .= " in {$method->getName()}" . substr(Dumper::toLine($args), 5);
throw $e;
}
}
}
}
示例9: render
/**
* Renders debug bar.
* @return void
*/
public function render()
{
@session_start();
// @ session may be already started or it is not possible to start session
$session =& $_SESSION['__NF']['tracybar-2.3'];
$redirect = preg_match('#^Location:#im', implode("\n", headers_list()));
if ($redirect) {
Dumper::fetchLiveData();
Dumper::$livePrefix = count($session) . 'p';
}
$obLevel = ob_get_level();
$panels = array();
foreach ($this->panels as $id => $panel) {
$idHtml = preg_replace('#[^a-z0-9]+#i', '-', $id);
try {
$tab = (string) $panel->getTab();
$panelHtml = $tab ? (string) $panel->getPanel() : NULL;
if ($tab && $panel instanceof \Nette\Diagnostics\IBarPanel) {
$panelHtml = preg_replace('~(["\'.\\s#])nette-(debug|inner|collapsed|toggle|toggle-collapsed)(["\'\\s])~', '$1tracy-$2$3', $panelHtml);
$panelHtml = str_replace('tracy-toggle-collapsed', 'tracy-toggle tracy-collapsed', $panelHtml);
}
$panels[] = array('id' => $idHtml, 'tab' => $tab, 'panel' => $panelHtml);
} catch (\Throwable $e) {
} catch (\Exception $e) {
}
if (isset($e)) {
$panels[] = array('id' => "error-{$idHtml}", 'tab' => "Error in {$id}", 'panel' => '<h1>Error: ' . $id . '</h1><div class="tracy-inner">' . nl2br(htmlSpecialChars($e, ENT_IGNORE, 'UTF-8')) . '</div>');
while (ob_get_level() > $obLevel) {
// restore ob-level if broken
ob_end_clean();
}
}
}
if ($redirect) {
$session[] = array('panels' => $panels, 'liveData' => Dumper::fetchLiveData());
return;
}
$liveData = Dumper::fetchLiveData();
foreach (array_reverse((array) $session) as $reqId => $info) {
$panels[] = array('tab' => '<span title="Previous request before redirect">previous</span>', 'panel' => NULL, 'previous' => TRUE);
foreach ($info['panels'] as $panel) {
$panel['id'] .= '-' . $reqId;
$panels[] = $panel;
}
$liveData += $info['liveData'];
}
$session = NULL;
require __DIR__ . '/assets/Bar/bar.phtml';
}
示例10: dump
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";
}
示例11: render
/**
* Renders debug bar.
* @return void
*/
public function render()
{
$useSession = $this->useSession && session_status() === PHP_SESSION_ACTIVE;
$redirectQueue =& $_SESSION['_tracy']['redirect'];
foreach (['bar', 'redirect', 'bluescreen'] as $key) {
$queue =& $_SESSION['_tracy'][$key];
$queue = array_slice((array) $queue, -10, NULL, TRUE);
$queue = array_filter($queue, function ($item) {
return isset($item['time']) && $item['time'] > time() - 60;
});
}
if (!Helpers::isHtmlMode() && !Helpers::isAjax()) {
return;
} elseif (Helpers::isAjax()) {
$rows[] = (object) ['type' => 'ajax', 'panels' => $this->renderPanels('-ajax')];
$dumps = Dumper::fetchLiveData();
$contentId = $useSession ? $_SERVER['HTTP_X_TRACY_AJAX'] . '-ajax' : NULL;
} elseif (preg_match('#^Location:#im', implode("\n", headers_list()))) {
// redirect
Dumper::fetchLiveData();
Dumper::$livePrefix = count($redirectQueue) . 'p';
$redirectQueue[] = ['panels' => $this->renderPanels('-r' . count($redirectQueue)), 'dumps' => Dumper::fetchLiveData(), 'time' => time()];
return;
} else {
$rows[] = (object) ['type' => 'main', 'panels' => $this->renderPanels()];
$dumps = Dumper::fetchLiveData();
foreach (array_reverse((array) $redirectQueue) as $info) {
$rows[] = (object) ['type' => 'redirect', 'panels' => $info['panels']];
$dumps += $info['dumps'];
}
$redirectQueue = NULL;
$contentId = $useSession ? substr(md5(uniqid('', TRUE)), 0, 10) : NULL;
}
ob_start(function () {
});
require __DIR__ . '/assets/Bar/panels.phtml';
require __DIR__ . '/assets/Bar/bar.phtml';
$content = Helpers::fixEncoding(ob_get_clean());
if ($contentId) {
$_SESSION['_tracy']['bar'][$contentId] = ['content' => $content, 'dumps' => $dumps, 'time' => time()];
}
if (Helpers::isHtmlMode()) {
require __DIR__ . '/assets/Bar/loader.phtml';
}
}
示例12: dataUri
/**
*
* @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;
}
示例13: file_put_contents
$a->buildFromDirectory(dirname(__FILE__) . '/' . $backupFolder);
file_put_contents($backupFolder . '.tar.gz', gzencode(file_get_contents($backupFolder . '.tar'), 9));
fwrite(STDERR, "Compresion complete!" . PHP_EOL);
fwrite(STDERR, "Removing temp folders and files.." . PHP_EOL);
//remove other files
unlink(realpath($backupFolder . '.tar'));
deleteDir(realpath($backupFolder));
fwrite(STDERR, "Temp folders and files removed!" . PHP_EOL);
}
} catch (Exception $e) {
fwrite(STDERR, "{$e}" . PHP_EOL);
}
return;
//exit(1);
} else {
$dumper = new Dumper($host, $port, $database, $noHistory, $callbackFile, $inlineAttachment, $binaryAttachments, $prettyJsonOutput, $separateFiles, $timeStamp, $callbackFilter);
$dumper->download();
}
function deleteDir($dirPath)
{
if (!is_dir($dirPath)) {
throw new InvalidArgumentException("{$dirPath} must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
deleteDir($file);
} else {
示例14: fopen
<?php
include "../../class.dumper.php";
$fp = fopen(__FILE__, "r");
$a = array('first' => $fp, 'last' => new bar(), 'null_var' => NULL, 'float' => pi(), 'bool' => true, ' leading_space' => 6 * 8, 'trailing_space ' => 'grapes', 'middle space' => 'Mt. Rushmore', 'phones' => array(5036541278, 8714077831, 'x253'), 'long_str' => "This is a really long string full of a\n bunch of crap that should eventually wrap. There once was a man from New Mexico...", 'empty_arr' => array(), 'func_str' => 'preg_replace', 'address' => array('street' => '123 Fake Street', 'city' => 'Portland', 'state' => 'Maine'), 'unixtime' => 1231241234, 'microtime' => microtime(1));
if (isset($_GET['short'])) {
Dumper::$expand_all = 1;
kd($a);
}
print "<h2>Dumper capture</h2>\n";
$str = k(array('foo' => 'bar'), KRUMO_CAPTURE);
print $str;
print "<h2>Dumper</h2>\n";
k(array('likes', 'kittens', 'and', 'dogs'));
print "<h2>Dumper passing multiple args</h2>\n";
k('likes', 'kittens', 'and', 'dogs');
print "<h2>Dumper + die()</h2>\n";
kd($a);
print "If you see this something is broken";
$k = new Dumper();
class bar
{
public $b = 'bb';
public $a = 'aa';
function foo()
{
return 'bar';
}
}
示例15: runMethod
/**
* Runs the test method.
* @return void
*/
private function runMethod($method)
{
$method = new \ReflectionMethod($this, $method);
if (!$method->isPublic()) {
throw new TestCaseException("Method {$method->getName()} is not public. Make it public or rename it.");
}
$data = array();
$info = Helpers::parseDocComment($method->getDocComment()) + array('dataprovider' => NULL, 'throws' => NULL);
if ($info['throws'] === '') {
throw new TestCaseException("Missing class name in @throws annotation for {$method->getName()}().");
} elseif (is_array($info['throws'])) {
throw new TestCaseException("Annotation @throws for {$method->getName()}() can be specified only once.");
} else {
$throws = preg_split('#\\s+#', $info['throws'], 2) + array(NULL, NULL);
}
$defaultParams = array();
foreach ($method->getParameters() as $param) {
$defaultParams[$param->getName()] = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : NULL;
}
foreach ((array) $info['dataprovider'] as $provider) {
$res = $this->getData($provider);
if (!is_array($res)) {
throw new TestCaseException("Data provider {$provider}() doesn't return array.");
}
foreach ($res as $set) {
$data[] = is_string(key($set)) ? array_merge($defaultParams, $set) : $set;
}
}
if (!$info['dataprovider']) {
if ($method->getNumberOfRequiredParameters()) {
throw new TestCaseException("Method {$method->getName()}() has arguments, but @dataProvider is missing.");
}
$data[] = array();
}
foreach ($data as $args) {
try {
if ($info['throws']) {
$tmp = $this;
$e = Assert::error(function () use($tmp, $method, $args) {
$tmp->runTest($method->getName(), $args);
}, $throws[0], $throws[1]);
if ($e instanceof AssertException) {
throw $e;
}
} else {
$this->runTest($method->getName(), $args);
}
} catch (AssertException $e) {
throw $e->setMessage("{$e->origMessage} in {$method->getName()}" . substr(Dumper::toLine($args), 5));
}
}
}