You are here

private static function Inline::evaluateScalar in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Symfony/Component/Yaml/Inline.php \Symfony\Component\Yaml\Inline::evaluateScalar()
  2. 7.2 vendor/Symfony/Component/Yaml/Inline.php \Symfony\Component\Yaml\Inline::evaluateScalar()

Evaluates scalars and replaces magic values.

Parameters

string $scalar:

Return value

string A YAML string

1 call to Inline::evaluateScalar()
Inline::parseScalar in vendor/Symfony/Component/Yaml/Inline.php
Parses a scalar to a YAML string.

File

vendor/Symfony/Component/Yaml/Inline.php, line 385

Class

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

Namespace

Symfony\Component\Yaml

Code

private static function evaluateScalar($scalar) {
  $scalar = trim($scalar);
  switch (true) {
    case 'null' == strtolower($scalar):
    case '' == $scalar:
    case '~' == $scalar:
      return null;
    case 0 === strpos($scalar, '!str'):
      return (string) substr($scalar, 5);
    case 0 === strpos($scalar, '! '):
      return intval(self::parseScalar(substr($scalar, 2)));
    case 0 === strpos($scalar, '!!php/object:'):
      if (self::$objectSupport) {
        return unserialize(substr($scalar, 13));
      }
      if (self::$exceptionOnInvalidType) {
        throw new ParseException('Object support when parsing a YAML file has been disabled.');
      }
      return null;
    case ctype_digit($scalar):
      $raw = $scalar;
      $cast = intval($scalar);
      return '0' == $scalar[0] ? octdec($scalar) : ((string) $raw == (string) $cast ? $cast : $raw);
    case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
      $raw = $scalar;
      $cast = intval($scalar);
      return '0' == $scalar[1] ? octdec($scalar) : ((string) $raw == (string) $cast ? $cast : $raw);
    case 'true' === strtolower($scalar):
      return true;
    case 'false' === strtolower($scalar):
      return false;
    case is_numeric($scalar):
      return '0x' == $scalar[0] . $scalar[1] ? hexdec($scalar) : floatval($scalar);
    case 0 == strcasecmp($scalar, '.inf'):
    case 0 == strcasecmp($scalar, '.NaN'):
      return -log(0);
    case 0 == strcasecmp($scalar, '-.inf'):
      return log(0);
    case preg_match('/^(-|\\+)?[0-9,]+(\\.[0-9]+)?$/', $scalar):
      return floatval(str_replace(',', '', $scalar));
    case preg_match(self::getTimestampRegex(), $scalar):
      return strtotime($scalar);
    default:
      return (string) $scalar;
  }
}