private static function Inline::evaluateScalar in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/yaml/Inline.php \Symfony\Component\Yaml\Inline::evaluateScalar()
Evaluates scalars and replaces magic values.
Parameters
string $scalar:
array $references:
Return value
string A YAML string
Throws
ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
1 call to Inline::evaluateScalar()
- Inline::parseScalar in vendor/
symfony/ yaml/ Inline.php - Parses a scalar to a YAML string.
File
- vendor/
symfony/ yaml/ Inline.php, line 432
Class
- Inline
- Inline implements a YAML parser/dumper for the YAML inline syntax.
Namespace
Symfony\Component\YamlCode
private static function evaluateScalar($scalar, $references = array()) {
$scalar = trim($scalar);
$scalarLower = strtolower($scalar);
if (0 === strpos($scalar, '*')) {
if (false !== ($pos = strpos($scalar, '#'))) {
$value = substr($scalar, 1, $pos - 2);
}
else {
$value = substr($scalar, 1);
}
// an unquoted *
if (false === $value || '' === $value) {
throw new ParseException('A reference must contain at least one character.');
}
if (!array_key_exists($value, $references)) {
throw new ParseException(sprintf('Reference "%s" does not exist.', $value));
}
return $references[$value];
}
switch (true) {
case 'null' === $scalarLower:
case '' === $scalar:
case '~' === $scalar:
return;
case 'true' === $scalarLower:
return true;
case 'false' === $scalarLower:
return false;
// Optimise for returning strings.
case $scalar[0] === '+' || $scalar[0] === '-' || $scalar[0] === '.' || $scalar[0] === '!' || is_numeric($scalar[0]):
switch (true) {
case 0 === strpos($scalar, '!str'):
return (string) substr($scalar, 5);
case 0 === strpos($scalar, '! '):
return (int) 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;
case 0 === strpos($scalar, '!!float '):
return (double) substr($scalar, 8);
case ctype_digit($scalar):
$raw = $scalar;
$cast = (int) $scalar;
return '0' == $scalar[0] ? octdec($scalar) : ((string) $raw == (string) $cast ? $cast : $raw);
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
$raw = $scalar;
$cast = (int) $scalar;
return '0' == $scalar[1] ? octdec($scalar) : ((string) $raw === (string) $cast ? $cast : $raw);
case is_numeric($scalar):
case preg_match(self::getHexRegex(), $scalar):
return '0x' === $scalar[0] . $scalar[1] ? hexdec($scalar) : (double) $scalar;
case '.inf' === $scalarLower:
case '.nan' === $scalarLower:
return -log(0);
case '-.inf' === $scalarLower:
return log(0);
case preg_match('/^(-|\\+)?[0-9,]+(\\.[0-9]+)?$/', $scalar):
return (double) str_replace(',', '', $scalar);
case preg_match(self::getTimestampRegex(), $scalar):
return strtotime($scalar);
}
default:
return (string) $scalar;
}
}