本文整理汇总了PHP中Symfony\Component\VarDumper\Dumper\CliDumper类的典型用法代码示例。如果您正苦于以下问题:PHP CliDumper类的具体用法?PHP CliDumper怎么用?PHP CliDumper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CliDumper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: appendLog
/**
* @param mixed $var
*/
function appendLog($var)
{
static $handler = null;
if ($handler === null) {
$logDir = LOG_DIR;
assert(is_dir($logDir), 'log dir "' . $logDir . '" must be a dir');
$logDir .= '/' . date('Ymd');
if (!is_dir($logDir)) {
$success = mkdir($logDir);
assert($success, 'log dir create failed: ' . $logDir . ': ' . json_encode(error_get_last()));
}
$logFile = $logDir . '/' . GAME_VERSION;
$cloner = new VarCloner();
$dumper = new CliDumper($logFile);
$handler = function ($var) use($cloner, $dumper) {
$dumper->dump($cloner->cloneVar($var));
};
}
$origHandler = VarDumper::setHandler($handler);
VarDumper::dump(date('c'));
foreach (func_get_args() as $var) {
VarDumper::dump($var);
}
VarDumper::setHandler($origHandler);
}
示例2: boot
public function boot(Application $app)
{
// This code is here to lazy load the dump stack. This default
// configuration for CLI mode is overridden in HTTP mode on
// 'kernel.request' event
VarDumper::setHandler(function ($var) use($app) {
$dumper = new CliDumper();
$dumper->dump($app['var_dumper.cloner']->cloneVar($var));
});
}
示例3: getVarDumperDump
private function getVarDumperDump($data)
{
$h = fopen('php://memory', 'r+b');
$cloner = new VarCloner();
$dumper = new CliDumper($h);
$dumper->setColors(false);
$dumper->dump($cloner->cloneVar($data)->withRefHandles(false));
$data = stream_get_contents($h, -1, 0);
fclose($h);
return rtrim($data);
}
示例4: format
/**
* {@inheritdoc}
*/
public function format($response)
{
$temp = tmpfile();
$cloner = new VarCloner();
$dumper = new CliDumper($temp);
$dumper->dump($cloner->cloneVar($response));
fseek($temp, 0);
$response = stream_get_contents($temp);
fclose($temp);
return $response;
}
示例5: getDump
protected function getDump($data)
{
$flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0;
$flags |= getenv('DUMP_STRING_LENGTH') ? CliDumper::DUMP_STRING_LENGTH : 0;
$h = fopen('php://memory', 'r+b');
$cloner = new VarCloner();
$cloner->setMaxItems(-1);
$dumper = new CliDumper($h, null, $flags);
$dumper->setColors(false);
$dumper->dump($cloner->cloneVar($data)->withRefHandles(false));
$data = stream_get_contents($h, -1, 0);
fclose($h);
return rtrim($data);
}
示例6: getDump
protected function getDump($data, $key = null)
{
$flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0;
$flags |= getenv('DUMP_STRING_LENGTH') ? CliDumper::DUMP_STRING_LENGTH : 0;
$cloner = new VarCloner();
$cloner->setMaxItems(-1);
$dumper = new CliDumper(null, null, $flags);
$dumper->setColors(false);
$data = $cloner->cloneVar($data)->withRefHandles(false);
if (null !== $key && null === ($data = $data->seek($key))) {
return;
}
return rtrim($dumper->dump($data, true));
}
示例7: boot
public function boot()
{
if ($this->container->getParameter('kernel.debug')) {
$container = $this->container;
// This code is here to lazy load the dump stack. This default
// configuration for CLI mode is overridden in HTTP mode on
// 'kernel.request' event
VarDumper::setHandler(function ($var) use($container) {
$dumper = new CliDumper();
$cloner = $container->get('var_dumper.cloner');
$handler = function ($var) use($dumper, $cloner) {
$dumper->dump($cloner->cloneVar($var));
};
VarDumper::setHandler($handler);
$handler($var);
});
}
}
示例8: __destruct
public function __destruct()
{
if (0 === $this->clonesCount-- && !$this->isCollected && $this->data) {
$this->clonesCount = 0;
$this->isCollected = true;
$h = headers_list();
$i = count($h);
array_unshift($h, 'Content-Type: ' . ini_get('default_mimetype'));
while (0 !== stripos($h[$i], 'Content-Type:')) {
--$i;
}
if ('cli' !== PHP_SAPI && stripos($h[$i], 'html')) {
$dumper = new HtmlDumper('php://output', $this->charset);
} else {
$dumper = new CliDumper('php://output', $this->charset);
$dumper->setColors(false);
}
foreach ($this->data as $i => $dump) {
$this->data[$i] = null;
if ($dumper instanceof HtmlDumper) {
$dump['name'] = $this->htmlEncode($dump['name']);
$dump['file'] = $this->htmlEncode($dump['file']);
if ('' !== $dump['file']) {
if ($this->fileLinkFormat) {
$link = strtr($this->fileLinkFormat, array('%f' => $dump['file'], '%l' => $dump['line']));
$dump['name'] = sprintf('<a href="%s" title="%s">%s</a>', $link, $dump['file'], $dump['name']);
} else {
$dump['name'] = sprintf('<abbr title="%s">%s</abbr>', $dump['file'], $dump['name']);
}
}
echo "\n<span class=\"sf-dump-meta\">{$dump['name']} on line {$dump['line']}:</span>";
} else {
echo "{$dump['name']} on line {$dump['line']}:\n";
}
$dumper->dump($dump['data']);
}
$this->data = array();
$this->dataCount = 0;
}
}
示例9: testBuggyRefs
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testBuggyRefs()
{
if (PHP_VERSION_ID >= 50600) {
$this->markTestSkipped('PHP 5.6 fixed refs counting');
}
$var = $this->getSpecialVars();
$var = $var[0];
$dumper = new CliDumper();
$dumper->setColors(false);
$cloner = new VarCloner();
$data = $cloner->cloneVar($var)->withMaxDepth(3);
$out = '';
$dumper->dump($data, function ($line, $depth) use(&$out) {
if ($depth >= 0) {
$out .= str_repeat(' ', $depth) . $line . "\n";
}
});
$this->assertSame(<<<EOTXT
array:1 [
0 => array:1 [
0 => array:1 [
0 => array:1 [ …1]
]
]
]
EOTXT
, $out);
}
示例10: inlineData
private function inlineData(array $extraction)
{
$dumper = new CliDumper();
$inlined = array();
foreach ($extraction as $k => $v) {
if (is_array($v)) {
$inlined[$k] = $this->inlineData($v);
} elseif ($v instanceof Data) {
$inlined[$k] = rtrim($dumper->dump($v->withRefHandles(false), true));
} else {
$inlined[$k] = $v;
}
}
return $inlined;
}
示例11: replaceDefaultSymfonyLineDumpers
/**
* Replaces the default output stream of Symfony's
* CliDumper and HtmlDumper classes in order to
* be able to run on Google App Engine.
*
* 'php://stdout' is used by CliDumper,
* 'php://output' is used by HtmlDumper,
* both are not supported on GAE.
*/
protected function replaceDefaultSymfonyLineDumpers()
{
HtmlDumper::$defaultOutput = CliDumper::$defaultOutput = function ($line, $depth, $indentPad) {
if (-1 !== $depth) {
echo str_repeat($indentPad, $depth) . $line . PHP_EOL;
}
};
}
示例12: dump
/**
* Dump a value with elegance.
*
* @param mixed $value
*
* @return void
*/
public function dump($value)
{
$dumper = new CliDumper();
$dumper->dump((new VarCloner())->cloneVar($value));
}
示例13: escape
/**
* @param string $input
*
* @return mixed
*/
public function escape($input)
{
$this->dumper->dump($this->cloner->cloneVar($input), $this->memoryStream);
$output = stream_get_contents($this->memoryStream, -1, 0);
ftruncate($this->memoryStream, 0);
return rtrim($output, "\n");
}
示例14: dump
/**
* @param $variable
* @return resource|string
* @throws Exception
* @throws null
*/
protected function dump($variable)
{
$output = fopen('php://memory', 'r+b');
$this->dumper->dump($this->cloner->cloneVar($variable), $output);
rewind($output);
$output = stream_get_contents($output);
return $output;
}
示例15: describeViewComposer
/**
* Describe a View Composer for logging.
* @param View $view View being created
* @param mixed $viewComposer View Composer
* @return string
*/
protected function describeViewComposer(View $view, $viewComposer)
{
$description = "View Composer called for view '{$view->name()}': ";
$this->cliDumper->dump($this->varCloner->cloneVar($viewComposer), function ($line, $depth) use(&$description) {
$description .= "{$line} ";
});
return $description;
}