/** * Parses a YAML value. * * @param string $value A YAML value * @param Boolean $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise * @param Boolean $objectSupport True if object support is enabled, false otherwise * * @return mixed A PHP value * * @throws ParseException When reference does not exist */ private function parseValue($value, $exceptionOnInvalidType, $objectSupport) { if (0 === strpos($value, '*')) { if (false !== ($pos = strpos($value, '#'))) { $value = substr($value, 1, $pos - 2); } else { $value = substr($value, 1); } if (!array_key_exists($value, $this->refs)) { throw new ParseException(sprintf('Reference "%s" does not exist.', $value), $this->currentLine); } return $this->refs[$value]; } if (preg_match('/^' . self::FOLDED_SCALAR_PATTERN . '$/', $value, $matches)) { $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : ''; return $this->parseFoldedScalar($matches['separator'], preg_replace('#\\d+#', '', $modifiers), intval(abs($modifiers))); } try { return Inline::parse($value, $exceptionOnInvalidType, $objectSupport); } catch (ParseException $e) { $e->setParsedLine($this->getRealCurrentLineNb() + 1); $e->setSnippet($this->currentLine); throw $e; } }
/** * @expectedException \Kernel\Decoder\Yaml\Exception\ParseException */ public function testParseInvalidSequenceShouldThrowException() { Inline::parse('{ foo: bar } bar'); }