Lines Matching refs:value

28     public const REFERENCE_PATTERN = '#^&(?P<ref>[^ ]++) *+(?P<value>.*)#u';
43 * Parses a YAML file into a PHP value.
72 * Parses a YAML string to a PHP value.
74 * @param string $value A YAML string
81 public function parse(string $value, int $flags = 0)
83 if (false === preg_match('//u', $value)) {
84 throw new ParseException('The YAML value does not appear to be valid UTF-8.', -1, null, $this->filename);
97 $data = $this->doParse($value, $flags);
116 private function doParse(string $value, int $flags)
120 $value = $this->cleanup($value);
121 $this->lines = explode("\n", $value);
161 if ('-' === $this->currentLine[0] && self::preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+))?$#u', rtrim($this->currentLine), $values)) {
167 if (isset($values['value']) && '&' === $values['value'][0] && self::preg_match(self::REFERENCE_PATTERN, $values['value'], $matches)) {
170 $values['value'] = $matches['value'];
173 if (isset($values['value'][1]) && '?' === $values['value'][0] && ' ' === $values['value'][1]) {
178 if (isset($values['value']) && 0 === strpos(ltrim($values['value'], ' '), '-')) {
187 } elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
189 } elseif (null !== $subTag = $this->getLineTag(ltrim($values['value'], ' '), $flags)) {
198 '!' === $values['value'][0]
199 || self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->trimTag($values['value']), $matches)
203 $block = $values['value'];
210 $data[] = $this->parseValue($values['value'], $flags, $context);
218 self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(( |\t)++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
244 if ('<<' === $key && (!isset($values['value']) || '&' !== $values['value'][0] || !self::preg_match('#^&(?P<ref>[^ ]+)#u', $values['value'], $refMatches))) {
247 if (isset($values['value'][0]) && '*' === $values['value'][0]) {
248 $refName = substr(rtrim($values['value']), 1);
264 throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
269 if (isset($values['value']) && '' !== $values['value']) {
270 $value = $values['value'];
272 $value = $this->getNextEmbedBlock();
274 $parsed = $this->parseBlock($this->getRealCurrentLineNb() + 1, $value, $flags);
281 throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
285 // If the value associated with the merge key is a sequence, then this sequence is expected to contain mapping nodes
300 // If the value associated with the key is a single mapping node, each of its key/value pairs is inserted into the
305 } elseif ('<<' !== $key && isset($values['value']) && '&' === $values['value'][0] && self::preg_match(self::REFERENCE_PATTERN, $values['value'], $matches)) {
308 $values['value'] = $matches['value'];
314 } elseif (!isset($values['value']) || '' === $values['value'] || 0 === strpos($values['value'], '#') || (null !== $subTag = $this->getLineTag($values['value'], $flags)) || '<<' === $key) {
316 // if next line is less indented or equal, then it means that the current value is null
332 $value = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(), $flags);
334 $this->refs[$refMatches['ref']] = $value;
336 if (Yaml::PARSE_OBJECT_FOR_MAP & $flags && $value instanceof \stdClass) {
337 $value = (array) $value;
340 $data += $value;
345 $data[$key] = new TaggedValue($subTag, $value);
347 $data[$key] = $value;
354 $value = $this->parseValue(rtrim($values['value']), $flags, $context);
358 $data[$key] = $value;
433 if (\is_string($value) && $this->lines[0] === trim($value)) {
435 $value = Inline::parse($this->lines[0], $flags, $this->refs);
443 return $value;
446 // try to parse the value as a multi-line string as a last resort
450 $value = '';
467 $value .= "\n";
469 $value .= ' ';
473 $value .= ltrim(substr($line, 0, -1));
475 $value .= $trimmedLine;
491 return Inline::parse(trim($value));
508 foreach ($data as $key => $value) {
509 $object->$key = $value;
711 * Parses a YAML value.
713 * @param string $value A YAML value
721 private function parseValue(string $value, int $flags, string $context)
723 if (0 === strpos($value, '*')) {
724 if (false !== $pos = strpos($value, '#')) {
725 $value = substr($value, 1, $pos - 2);
727 $value = substr($value, 1);
730 if (!\array_key_exists($value, $this->refs)) {
731 if (false !== $pos = array_search($value, $this->refsBeingParsed, true)) {
732 throw new ParseException(sprintf('Circular reference [%s] detected for reference "%s".', implode(', ', array_merge(\array_slice($this->refsBeingParsed, $pos), [$value])), $value), $this->currentLineNb + 1, $this->currentLine, $this->filename);
735 throw new ParseException(sprintf('Reference "%s" does not exist.', $value), $this->currentLineNb + 1, $this->currentLine, $this->filename);
738 return $this->refs[$value];
741 if (\in_array($value[0], ['!', '|', '>'], true) && self::preg_match('/^(?:'.self::TAG_PATTERN.' +)?'.self::BLOCK_SCALAR_HEADER_PATTERN.'$/', $value, $matches)) {
758 if ('' !== $value && '{' === $value[0]) {
759 $cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));
762 } elseif ('' !== $value && '[' === $value[0]) {
763 $cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));
768 switch ($value[0] ?? '') {
771 $cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));
795 $value .= "\n";
798 $value .= $lines[$i];
801 $value .= ' '.$lines[$i];
808 $parsedValue = Inline::parse($value, $flags, $this->refs);
810 if ('mapping' === $context && \is_string($parsedValue) && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
811 throw new ParseException('A colon cannot be used in an unquoted mapping value.', $this->getRealCurrentLineNb() + 1, $value, $this->filename);
999 * @param string $value The input YAML string
1001 private function cleanup(string $value): string
1003 $value = str_replace(["\r\n", "\r"], "\n", $value);
1007 $value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#u', '', $value, -1, $count);
1011 $trimmedValue = preg_replace('#^(\#.*?\n)+#s', '', $value, -1, $count);
1014 $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
1015 $value = $trimmedValue;
1019 $trimmedValue = preg_replace('#^\-\-\-.*?\n#s', '', $value, -1, $count);
1022 $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
1023 $value = $trimmedValue;
1026 $value = preg_replace('#\.\.\.\s*$#', '', $value);
1029 return $value;
1112 * Trim the tag on top of the value.
1117 private function trimTag(string $value): string
1119 if ('!' === $value[0]) {
1120 return ltrim(substr($value, 1, strcspn($value, " \r\n", 1)), ' ');
1123 return $value;
1126 private function getLineTag(string $value, int $flags, bool $nextLineCheck = true): ?string
1128 if ('' === $value || '!' !== $value[0] || 1 !== self::preg_match('/^'.self::TAG_PATTERN.' *( +#.*)?$/', $value, $matches)) {
1140 throw new ParseException(sprintf('The built-in tag "!%s" is not implemented.', $tag), $this->getRealCurrentLineNb() + 1, $value, $this->filename);
1147 throw new ParseException(sprintf('Tags support is not enabled. You must use the flag "Yaml::PARSE_CUSTOM_TAGS" to use "%s".', $matches['tag']), $this->getRealCurrentLineNb() + 1, $value, $this->filename);
1153 $value = $quotation;
1166 $value .= "\n";
1168 $value .= ' ';
1175 $value .= '\\';
1177 $value .= '\\'.$this->currentLine[$cursor];
1185 $value .= "''";
1189 return $value.$quotation;
1191 $value .= $this->currentLine[$cursor];
1238 $value = $this->currentLine[$cursor];
1248 $value .= $this->lexInlineQuotedString($cursor);
1252 $value .= $this->currentLine[$cursor];
1256 $value .= $this->lexInlineMapping($cursor);
1259 $value .= $this->lexInlineSequence($cursor);
1262 $value .= $this->currentLine[$cursor];
1265 return $value;
1269 $value .= $this->lexUnquotedString($cursor);
1273 $value .= ' ';