You are here

public static function Inline::dump in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/symfony/yaml/Inline.php \Symfony\Component\Yaml\Inline::dump()

Dumps a given PHP variable to a YAML string.

Parameters

mixed $value The PHP variable to convert:

bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise:

bool $objectSupport true if object support is enabled, false otherwise:

Return value

string The YAML string representing the PHP array

Throws

DumpException When trying to dump PHP resource

5 calls to Inline::dump()
Dumper::dump in vendor/symfony/yaml/Symfony/Component/Yaml/Dumper.php
Dumps a PHP value to YAML.
Inline::dumpArray in vendor/symfony/yaml/Symfony/Component/Yaml/Inline.php
Dumps a PHP array to a YAML string.
InlineTest::testDump in vendor/symfony/yaml/Symfony/Component/Yaml/Tests/InlineTest.php
InlineTest::testDumpNumericValueWithLocale in vendor/symfony/yaml/Symfony/Component/Yaml/Tests/InlineTest.php
InlineTest::testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF in vendor/symfony/yaml/Symfony/Component/Yaml/Tests/InlineTest.php

File

vendor/symfony/yaml/Symfony/Component/Yaml/Inline.php, line 94

Class

Inline
Inline implements a YAML parser/dumper for the YAML inline syntax.

Namespace

Symfony\Component\Yaml

Code

public static function dump($value, $exceptionOnInvalidType = false, $objectSupport = false) {
  switch (true) {
    case is_resource($value):
      if ($exceptionOnInvalidType) {
        throw new DumpException(sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value)));
      }
      return 'null';
    case is_object($value):
      if ($objectSupport) {
        return '!php/object:' . serialize($value);
      }
      if ($exceptionOnInvalidType) {
        throw new DumpException('Object support when dumping a YAML file has been disabled.');
      }
      return 'null';
    case is_array($value):
      return self::dumpArray($value, $exceptionOnInvalidType, $objectSupport);
    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');
      }
      $repr = is_string($value) ? "'{$value}'" : (is_infinite($value) ? str_ireplace('INF', '.Inf', (string) $value) : (string) $value);
      if (false !== $locale) {
        setlocale(LC_NUMERIC, $locale);
      }
      return $repr;
    case '' == $value:
      return "''";
    case Escaper::requiresDoubleQuoting($value):
      return Escaper::escapeWithDoubleQuotes($value);
    case Escaper::requiresSingleQuoting($value):
    case preg_match(self::getHexRegex(), $value):
    case preg_match(self::getTimestampRegex(), $value):
      return Escaper::escapeWithSingleQuotes($value);
    default:
      return $value;
  }
}