Lines Matching defs:value

51      * Converts a YAML string to a PHP value.
53 * @param string|null $value A YAML string
61 public static function parse(string $value = null, int $flags = 0, array &$references = [])
65 $value = trim($value);
67 if ('' === $value) {
78 $tag = self::parseTag($value, $i, $flags);
79 switch ($value[$i]) {
81 $result = self::parseSequence($value, $flags, $i, $references);
85 $result = self::parseMapping($value, $flags, $i, $references);
89 $result = self::parseScalar($value, $flags, null, $i, true, $references);
93 if (preg_replace('/\s*#.*$/A', '', substr($value, $i))) {
94 throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
112 * @param mixed $value The PHP variable to convert
117 public static function dump($value, int $flags = 0): string
120 case \is_resource($value):
122 throw new DumpException(sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value)));
126 case $value instanceof \DateTimeInterface:
127 return $value->format('c');
128 case $value instanceof \UnitEnum:
129 return sprintf('!php/const %s::%s', \get_class($value), $value->name);
130 case \is_object($value):
131 if ($value instanceof TaggedValue) {
132 return '!'.$value->getTag().' '.self::dump($value->getValue(), $flags);
136 return '!php/object '.self::dump(serialize($value));
139 if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
142 foreach ($value as $key => $val) {
154 case \is_array($value):
155 return self::dumpArray($value, $flags);
156 case null === $value:
158 case true === $value:
160 case false === $value:
162 case \is_int($value):
163 return $value;
164 case is_numeric($value) && false === strpbrk($value, "\f\n\r\t\v"):
169 if (\is_float($value)) {
170 $repr = (string) $value;
171 if (is_infinite($value)) {
173 } elseif (floor($value) == $value && $repr == $value) {
174 // Preserve float data type since storing a whole number will result in integer value.
180 $repr = \is_string($value) ? "'$value'" : (string) $value;
187 case '' == $value:
189 case self::isBinaryString($value):
190 return '!!binary '.base64_encode($value);
191 case Escaper::requiresDoubleQuoting($value):
192 return Escaper::escapeWithDoubleQuotes($value);
193 case Escaper::requiresSingleQuoting($value):
194 case Parser::preg_match('{^[0-9]+[_0-9]*$}', $value):
195 case Parser::preg_match(self::getHexRegex(), $value):
196 case Parser::preg_match(self::getTimestampRegex(), $value):
197 return Escaper::escapeWithSingleQuotes($value);
199 return $value;
206 * @param array|\ArrayObject|\stdClass $value The PHP array or array-like object to check
208 public static function isHash($value): bool
210 if ($value instanceof \stdClass || $value instanceof \ArrayObject) {
216 foreach ($value as $key => $val) {
228 * @param array $value The PHP array to dump
231 private static function dumpArray(array $value, int $flags): string
234 if (($value || Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE & $flags) && !self::isHash($value)) {
236 foreach ($value as $val) {
245 foreach ($value as $key => $val) {
368 $value = self::parseSequence($sequence, $flags, $i, $references);
372 $value = self::parseMapping($sequence, $flags, $i, $references);
375 $value = self::parseScalar($sequence, $flags, [',', ']'], $i, null === $tag, $references, $isQuoted);
377 // the value can be an array if a reference has been resolved to an array var
378 if (\is_string($value) && !$isQuoted && false !== strpos($value, ': ')) {
382 $value = self::parseMapping('{'.$value.'}', $flags, $pos, $references);
388 if (!$isQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
389 $references[$matches['ref']] = $matches['value'];
390 $value = $matches['value'];
397 $value = new TaggedValue($tag, $value);
400 $output[] = $value;
483 $value = self::parseSequence($mapping, $flags, $i, $references);
489 foreach ($value as $parsedValue) {
494 $output[$key] = new TaggedValue($tag, $value);
496 $output[$key] = $value;
504 $value = self::parseMapping($mapping, $flags, $i, $references);
510 $output += $value;
513 $output[$key] = new TaggedValue($tag, $value);
515 $output[$key] = $value;
522 $value = self::parseScalar($mapping, $flags, [',', '}', "\n"], $i, null === $tag, $references, $isValueQuoted);
528 $output += $value;
530 if (!$isValueQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
531 $references[$matches['ref']] = $matches['value'];
532 $value = $matches['value'];
536 $output[$key] = new TaggedValue($tag, $value);
538 $output[$key] = $value;
568 $value = substr($scalar, 1, $pos - 2);
570 $value = substr($scalar, 1);
574 if (false === $value || '' === $value) {
575 throw new ParseException('A reference must contain at least one character.', self::$parsedLineNumber + 1, $value, self::$parsedFilename);
578 if (!\array_key_exists($value, $references)) {
579 throw new ParseException(sprintf('Reference "%s" does not exist.', $value), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
582 return $references[$value];
612 trigger_deprecation('symfony/yaml', '5.1', 'Using the !php/object tag without a value is deprecated.');
628 trigger_deprecation('symfony/yaml', '5.1', 'Using the !php/const tag without a value is deprecated.');
652 case preg_match('/^(?:\+|-)?0o(?P<value>[0-7_]++)$/', $scalar, $matches):
653 $value = str_replace('_', '', $matches['value']);
656 return -octdec($value);
659 return octdec($value);
721 private static function parseTag(string $value, int &$i, int $flags): ?string
723 if ('!' !== $value[$i]) {
727 $tagLength = strcspn($value, " \t\n[]{},", $i + 1);
728 $tag = substr($value, $i + 1, $tagLength);
731 $nextOffset += strspn($value, ' ', $nextOffset);
733 if ('' === $tag && (!isset($value[$nextOffset]) || \in_array($value[$nextOffset], [']', '}', ','], true))) {
734 throw new ParseException('Using the unquoted scalar value "!" is not supported. You must quote it.', self::$parsedLineNumber + 1, $value, self::$parsedFilename);
738 if ('' !== $tag && (!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], ['[', '{'], true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) {
747 throw new ParseException(sprintf('The built-in tag "!%s" is not implemented.', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
750 if ('' !== $tag && !isset($value[$i])) {
751 throw new ParseException(sprintf('Missing value for tag "%s".', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
758 throw new ParseException(sprintf('Tags support is not enabled. Enable the "Yaml::PARSE_CUSTOM_TAGS" flag to use "!%s".', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
776 private static function isBinaryString(string $value): bool
778 return !preg_match('//u', $value) || preg_match('/[^\x00\x07-\x0d\x1B\x20-\xff]/', $value);