本文整理汇总了PHP中Symfony\Component\VarDumper\Cloner\VarCloner类的典型用法代码示例。如果您正苦于以下问题:PHP VarCloner类的具体用法?PHP VarCloner怎么用?PHP VarCloner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VarCloner类的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: testCloneVarStringWithScheme
public function testCloneVarStringWithScheme()
{
$c = new CloneVarDataCollector('scheme://foo');
$c->collect(new Request(), new Response());
$cloner = new VarCloner();
$this->assertEquals($cloner->cloneVar('scheme://foo'), $c->getData());
}
示例3: testCollect
public function testCollect()
{
$c = new RequestDataCollector();
$c->collect($request = $this->createRequest(), $this->createResponse());
$cloner = new VarCloner();
$attributes = $c->getRequestAttributes();
$this->assertSame('request', $c->getName());
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\HeaderBag', $c->getRequestHeaders());
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestServer());
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestCookies());
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $attributes);
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestRequest());
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestQuery());
$this->assertSame('html', $c->getFormat());
$this->assertEquals('foobar', $c->getRoute());
$this->assertEquals($cloner->cloneVar(array('name' => 'foo')), $c->getRouteParams());
$this->assertSame(array(), $c->getSessionAttributes());
$this->assertSame('en', $c->getLocale());
$this->assertEquals($cloner->cloneVar($request->attributes->get('resource')), $attributes->get('resource'));
$this->assertEquals($cloner->cloneVar($request->attributes->get('object')), $attributes->get('object'));
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\HeaderBag', $c->getResponseHeaders());
$this->assertSame('OK', $c->getStatusText());
$this->assertSame(200, $c->getStatusCode());
$this->assertSame('application/json', $c->getContentType());
}
示例4: register
/**
* {@inheritdoc}
*/
public function register(Application $app)
{
$app['dump'] = $app->protect(function ($var) use($app) {
if (!$app['debug']) {
return;
}
$app['dumper']->dump($app['dumper.cloner']->cloneVar($var));
});
VarDumper::setHandler(function ($var) use($app) {
/*
* Referencing $app['dump'] in anonymous function
* so the closure can be replaced in $app without
* breaking the reference here.
*/
return $app['dump']($var);
});
$app['dumper'] = $app->share(function ($app) {
return PHP_SAPI === 'cli' ? $app['dumper.cli'] : $app['dumper.html'];
});
$app['dumper.cli'] = $app->share(function () {
return new CliDumper();
});
$app['dumper.html'] = $app->share(function () {
return new HtmlDumper();
});
$app['dumper.cloner'] = $app->share(function () {
$cloner = new VarCloner();
$cloner->addCasters(Caster\FilesystemCasters::getCasters());
return $cloner;
});
}
示例5: render
/**
* Renders data.
*
* @return string
*/
public function render()
{
$cloner = new VarCloner();
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
$output = fopen('php://memory', 'r+b');
$dumper->dump($cloner->cloneVar($this->getData()), $output);
return stream_get_contents($output, -1, 0);
}
示例6: boot
public function boot(Application $app)
{
VarDumper::setHandler(function ($var) {
$cloner = new VarCloner();
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
$dumper->dump($cloner->cloneVar($var));
});
}
示例7: geny_dump
public function geny_dump($data)
{
$stream = fopen('php://memory', 'r+b');
$dumper = new HtmlDumper($stream);
$cloner = new VarCloner();
$dumper->dump($cloner->cloneVar($data));
rewind($stream);
return stream_get_contents($stream);
}
示例8: dump
public static function dump($var)
{
if (null === self::$handler) {
$cloner = new VarCloner();
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
self::$handler = function ($var) use($cloner, $dumper) {
$dumper->dump($cloner->cloneVar($var));
};
}
return call_user_func(self::$handler, $var);
}
示例9: 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);
}
示例10: 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;
}
示例11: dump
/**
* It dumps the contents of the given variable. It tries several dumpers in
* turn (VarDumper component, Yaml::dump, etc.) and if none is available, it
* falls back to PHP's var_export().
*
* @param mixed $variable
*
* @return string
*/
public function dump($variable)
{
if (class_exists('Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper')) {
$cloner = new VarCloner();
$dumper = new HtmlDumper();
return $dumper->dump($cloner->cloneVar($variable));
} elseif (class_exists('Symfony\\Component\\Yaml\\Yaml')) {
return sprintf('<pre class="sf-dump">%s</pre>', Yaml::dump((array) $variable, 1024));
} else {
return sprintf('<pre class="sf-dump">%s</pre>', var_export($variable, true));
}
}
示例12: dumper
public static function dumper($obj)
{
ob_start();
$cloner = new VarCloner();
$dumper = new HtmlDumper();
self::$handler = function ($obj) use($cloner, $dumper) {
$dumper->dump($cloner->cloneVar($obj));
};
call_user_func(self::$handler, $obj);
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
示例13: 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);
}
示例14: testCollect
public function testCollect()
{
$cloner = new VarCloner();
$collectedMessages = array(array('id' => 'foo', 'translation' => 'foo (en)', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_DEFINED, 'parameters' => array(), 'transChoiceNumber' => null), array('id' => 'bar', 'translation' => 'bar (fr)', 'locale' => 'fr', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, 'parameters' => array(), 'transChoiceNumber' => null), array('id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'parameters' => array('%count%' => 3), 'transChoiceNumber' => 3), array('id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'parameters' => array('%count%' => 3), 'transChoiceNumber' => 3), array('id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'parameters' => array('%count%' => 4, '%foo%' => 'bar'), 'transChoiceNumber' => 4));
$expectedMessages = array(array('id' => 'foo', 'translation' => 'foo (en)', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_DEFINED, 'count' => 1, 'parameters' => array(), 'transChoiceNumber' => null), array('id' => 'bar', 'translation' => 'bar (fr)', 'locale' => 'fr', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, 'count' => 1, 'parameters' => array(), 'transChoiceNumber' => null), array('id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'count' => 3, 'parameters' => array($cloner->cloneVar(array('%count%' => 3)), $cloner->cloneVar(array('%count%' => 3)), $cloner->cloneVar(array('%count%' => 4, '%foo%' => 'bar'))), 'transChoiceNumber' => 3));
$translator = $this->getTranslator();
$translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue($collectedMessages));
$dataCollector = new TranslationDataCollector($translator);
$dataCollector->lateCollect();
$this->assertEquals(1, $dataCollector->getCountMissings());
$this->assertEquals(1, $dataCollector->getCountFallbacks());
$this->assertEquals(1, $dataCollector->getCountDefines());
$this->assertEquals($expectedMessages, array_values($dataCollector->getMessages()));
}
示例15: 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");
}