コード例 #1
0
 /**
  * @dataProvider getScalarIndicators
  * @expectedException components\tools\Yaml\Exception\ParseException
  * @expectedExceptionMessage cannot start a plain scalar; you need to quote the scalar.
  */
 public function testParseUnquotedScalarStartingWithScalarIndicator($indicator)
 {
     Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
 }
コード例 #2
0
ファイル: Parser.php プロジェクト: Antoine-Demailly/lighten
 /**
  * Parses a YAML value.
  *
  * @param string $value                  A YAML value
  * @param bool   $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise
  * @param bool   $objectSupport          True if object support is enabled, false otherwise
  * @param bool   $objectForMap           true if maps should return a stdClass instead of array()
  * @param string $context                The parser context (either sequence or mapping)
  *
  * @return mixed A PHP value
  *
  * @throws ParseException When reference does not exist
  */
 private function parseValue($value, $exceptionOnInvalidType, $objectSupport, $objectForMap, $context)
 {
     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::BLOCK_SCALAR_HEADER_PATTERN . '$/', $value, $matches)) {
         $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
         return $this->parseBlockScalar($matches['separator'], preg_replace('#\\d+#', '', $modifiers), (int) abs($modifiers));
     }
     try {
         $parsedValue = Inline::parse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
         if ('mapping' === $context && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
             throw new ParseException('A colon cannot be used in an unquoted mapping value.');
         }
         return $parsedValue;
     } catch (ParseException $e) {
         $e->setParsedLine($this->getRealCurrentLineNb() + 1);
         $e->setSnippet($this->currentLine);
         throw $e;
     }
 }