public static function Inline::dump in Lockr 7.3
Dumps a given PHP variable to a YAML string.
Parameters
mixed $value The PHP variable to convert:
int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string:
Return value
string The YAML string representing the PHP value
Throws
DumpException When trying to dump PHP resource
7 calls to Inline::dump()
- Dumper::dump in vendor/
symfony/ yaml/ Dumper.php - Dumps a PHP value to YAML.
- Inline::dumpArray in vendor/
symfony/ yaml/ Inline.php - Dumps a PHP array to a YAML string.
- InlineTest::testDump in vendor/
symfony/ yaml/ Tests/ InlineTest.php - @dataProvider getTestsForDump
- InlineTest::testDumpDateTime in vendor/
symfony/ yaml/ Tests/ InlineTest.php - @dataProvider getDateTimeDumpTests
- InlineTest::testDumpNumericValueWithLocale in vendor/
symfony/ yaml/ Tests/ InlineTest.php
File
- vendor/
symfony/ yaml/ Inline.php, line 156
Class
- Inline
- Inline implements a YAML parser/dumper for the YAML inline syntax.
Namespace
Symfony\Component\YamlCode
public static function dump($value, $flags = 0) {
if (\is_bool($flags)) {
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
if ($flags) {
$flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE;
}
else {
$flags = 0;
}
}
if (\func_num_args() >= 3) {
@trigger_error('Passing a boolean flag to toggle object support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
if (func_get_arg(2)) {
$flags |= Yaml::DUMP_OBJECT;
}
}
switch (true) {
case \is_resource($value):
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
throw new DumpException(sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value)));
}
return 'null';
case $value instanceof \DateTimeInterface:
return $value
->format('c');
case \is_object($value):
if ($value instanceof TaggedValue) {
return '!' . $value
->getTag() . ' ' . self::dump($value
->getValue(), $flags);
}
if (Yaml::DUMP_OBJECT & $flags) {
return '!php/object ' . self::dump(serialize($value));
}
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
return self::dumpArray($value, $flags & ~Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
}
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
throw new DumpException('Object support when dumping a YAML file has been disabled.');
}
return 'null';
case \is_array($value):
return self::dumpArray($value, $flags);
case null === $value:
return 'null';
case true === $value:
return 'true';
case false === $value:
return 'false';
case ctype_digit($value):
return \is_string($value) ? "'{$value}'" : (int) $value;
case is_numeric($value):
$locale = setlocale(LC_NUMERIC, 0);
if (false !== $locale) {
setlocale(LC_NUMERIC, 'C');
}
if (\is_float($value)) {
$repr = (string) $value;
if (is_infinite($value)) {
$repr = str_ireplace('INF', '.Inf', $repr);
}
elseif (floor($value) == $value && $repr == $value) {
// Preserve float data type since storing a whole number will result in integer value.
$repr = '!!float ' . $repr;
}
}
else {
$repr = \is_string($value) ? "'{$value}'" : (string) $value;
}
if (false !== $locale) {
setlocale(LC_NUMERIC, $locale);
}
return $repr;
case '' == $value:
return "''";
case self::isBinaryString($value):
return '!!binary ' . base64_encode($value);
case Escaper::requiresDoubleQuoting($value):
return Escaper::escapeWithDoubleQuotes($value);
case Escaper::requiresSingleQuoting($value):
case Parser::preg_match('{^[0-9]+[_0-9]*$}', $value):
case Parser::preg_match(self::getHexRegex(), $value):
case Parser::preg_match(self::getTimestampRegex(), $value):
return Escaper::escapeWithSingleQuotes($value);
default:
return $value;
}
}