當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Inline::parse方法代碼示例

本文整理匯總了PHP中Symfony\Component\Yaml\Inline::parse方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inline::parse方法的具體用法?PHP Inline::parse怎麽用?PHP Inline::parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Yaml\Inline的用法示例。


在下文中一共展示了Inline::parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getParameter

 /**
  * @param string $name
  *
  * @return array|string|bool|int|float|null
  */
 public function getParameter($name)
 {
     if (!isset($this->parameterMap[$name])) {
         return $this->container->getParameter($name);
     }
     $varName = $this->parameterMap[$name]['variable'];
     $var = getenv($varName);
     if (false === $var) {
         return $this->container->getParameter($name);
     }
     if ($this->parameterMap[$name]['yaml']) {
         return Inline::parse($var);
     }
     return $var;
 }
開發者ID:digitalkaoz,項目名稱:DynamicParametersBundle,代碼行數:20,代碼來源:ParameterRetriever.php

示例2: testDump

 public function testDump()
 {
     $testsForDump = $this->getTestsForDump();
     foreach ($testsForDump as $yaml => $value) {
         $this->assertEquals($yaml, Inline::dump($value), sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
     }
     foreach ($this->getTestsForParse() as $yaml => $value) {
         if ($value == 1230) {
             continue;
         }
         $this->assertEquals($value, Inline::parse(Inline::dump($value)), 'check consistency');
     }
     foreach ($testsForDump as $yaml => $value) {
         if ($value == 1230) {
             continue;
         }
         $this->assertEquals($value, Inline::parse(Inline::dump($value)), 'check consistency');
     }
 }
開發者ID:nightchiller,項目名稱:symfony,代碼行數:19,代碼來源:InlineTest.php

示例3: getFunctions

 public function getFunctions()
 {
     return array(new ExpressionFunction('dynamic_parameter', function ($paramName, $envVar) {
         return sprintf('(false === getenv(%s) ? $this->getParameter(%s) : getenv(%s))', $envVar, $paramName, $envVar);
     }, function (array $variables, $paramName, $envVar) {
         $envParam = getenv($envVar);
         if (false !== $envParam) {
             return $envParam;
         }
         return $variables['container']->getParameter($paramName);
     }), new ExpressionFunction('dynamic_yaml_parameter', function ($paramName, $envVar) {
         return sprintf('(false === getenv(%s) ? $this->getParameter(%s) : \\Symfony\\Component\\Yaml\\Inline::parse(getenv(%s)))', $envVar, $paramName, $envVar);
     }, function (array $variables, $paramName, $envVar) {
         $envParam = getenv($envVar);
         if (false !== $envParam) {
             return Inline::parse($envParam);
         }
         return $variables['container']->getParameter($paramName);
     }));
 }
開發者ID:digitalkaoz,項目名稱:DynamicParametersBundle,代碼行數:20,代碼來源:FunctionProvider.php

示例4: parseValue

 /**
  * Parses a YAML value.
  *
  * @param string $value   A YAML value
  * @param int    $flags   A bit field of PARSE_* constants to customize the YAML parser behavior
  * @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, $flags, $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->currentLineNb + 1, $this->currentLine);
         }
         return $this->refs[$value];
     }
     if (preg_match('/^' . self::TAG_PATTERN . self::BLOCK_SCALAR_HEADER_PATTERN . '$/', $value, $matches)) {
         $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
         $data = $this->parseBlockScalar($matches['separator'], preg_replace('#\\d+#', '', $modifiers), (int) abs($modifiers));
         if (isset($matches['tag']) && '!!binary' === $matches['tag']) {
             return Inline::evaluateBinaryScalar($data);
         }
         return $data;
     }
     try {
         Inline::$parsedLineNumber = $this->getRealCurrentLineNb();
         $parsedValue = Inline::parse($value, $flags, $this->refs);
         if ('mapping' === $context && is_string($parsedValue) && '"' !== $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;
     }
 }
開發者ID:Gladhon,項目名稱:symfony,代碼行數:45,代碼來源:Parser.php

示例5: getParams

 private function getParams(array $expectedParams, array $actualParams)
 {
     // Simply use the expectedParams value as default for the missing params.
     if (!$this->io->isInteractive()) {
         return array_replace($expectedParams, $actualParams);
     }
     $isStarted = false;
     foreach ($expectedParams as $key => $message) {
         if (array_key_exists($key, $actualParams)) {
             continue;
         }
         if (!$isStarted) {
             $isStarted = true;
             $this->io->write('<comment>Some parameters are missing. Please provide them.</comment>');
         }
         $default = Inline::dump($message);
         $value = $this->io->ask(sprintf('<question>%s</question> (<comment>%s</comment>): ', $key, $default), $default);
         $actualParams[$key] = Inline::parse($value);
     }
     return $actualParams;
 }
開發者ID:justasr,項目名稱:symfony2-front-back-structure,代碼行數:21,代碼來源:Processor.php

示例6: testNotSupportedMissingValue

 /**
  * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  * @expectedExceptionMessage Malformed inline YAML string: {this, is not, supported}.
  */
 public function testNotSupportedMissingValue()
 {
     Inline::parse('{this, is not, supported}');
 }
開發者ID:shegun-babs,項目名稱:dakrush,代碼行數:8,代碼來源:InlineTest.php

示例7: testParseUnquotedScalarStartingWithScalarIndicator

 /**
  * @dataProvider getScalarIndicators
  * @expectedException Symfony\Component\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));
 }
開發者ID:aaronleslie,項目名稱:aaronunix,代碼行數:9,代碼來源:InlineTest.php

示例8: parseValue

 /**
  * 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
  *
  * @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, $this->refs);
     } catch (ParseException $e) {
         $e->setParsedLine($this->getRealCurrentLineNb() + 1);
         $e->setSnippet($this->currentLine);
         throw $e;
     }
 }
開發者ID:mawaha,項目名稱:tracker,代碼行數:36,代碼來源:Parser.php

示例9: testParseInvalidBinaryData

 /**
  * @dataProvider getInvalidBinaryData
  */
 public function testParseInvalidBinaryData($data, $expectedMessage)
 {
     $this->setExpectedExceptionRegExp('\\Symfony\\Component\\Yaml\\Exception\\ParseException', $expectedMessage);
     Inline::parse($data);
 }
開發者ID:natmchugh,項目名稱:symfony,代碼行數:8,代碼來源:InlineTest.php

示例10: parseValue

 /**
  * Parses a YAML value.
  *
  * @param string $value   A YAML value
  * @param int    $flags   A bit field of PARSE_* constants to customize the YAML parser behavior
  * @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, $flags, $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->currentLineNb + 1, $this->currentLine);
         }
         return $this->refs[$value];
     }
     if (preg_match('/^' . self::TAG_PATTERN . self::BLOCK_SCALAR_HEADER_PATTERN . '$/', $value, $matches)) {
         $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
         $data = $this->parseBlockScalar($matches['separator'], preg_replace('#\\d+#', '', $modifiers), (int) abs($modifiers));
         if (isset($matches['tag']) && '!!binary' === $matches['tag']) {
             return Inline::evaluateBinaryScalar($data);
         }
         return $data;
     }
     try {
         $quotation = '' !== $value && ('"' === $value[0] || "'" === $value[0]) ? $value[0] : null;
         // do not take following lines into account when the current line is a quoted single line value
         if (null !== $quotation && preg_match('/^' . $quotation . '.*' . $quotation . '(\\s*#.*)?$/', $value)) {
             return Inline::parse($value, $flags, $this->refs);
         }
         while ($this->moveToNextLine()) {
             // unquoted strings end before the first unindented line
             if (null === $quotation && $this->getCurrentLineIndentation() === 0) {
                 $this->moveToPreviousLine();
                 break;
             }
             $value .= ' ' . trim($this->currentLine);
             // quoted string values end with a line that is terminated with the quotation character
             if ('' !== $this->currentLine && substr($this->currentLine, -1) === $quotation) {
                 break;
             }
         }
         Inline::$parsedLineNumber = $this->getRealCurrentLineNb();
         $parsedValue = Inline::parse($value, $flags, $this->refs);
         if ('mapping' === $context && is_string($parsedValue) && '"' !== $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;
     }
 }
開發者ID:ayoah,項目名稱:symfony,代碼行數:62,代碼來源:Parser.php

示例11: testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF

 public function testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF()
 {
     $value = '686e444';
     $this->assertSame($value, Inline::parse(Inline::dump($value)));
 }
開發者ID:sirdiego,項目名稱:importr,代碼行數:5,代碼來源:InlineTest.php

示例12: writeNodeQuestion

 /**
  * Present a node question to the user
  *
  * @param  NodeInterface $node The node in question
  * @param  string $name The name of the node
  * @return mixed The new value of the node
  */
 private function writeNodeQuestion($node, $name)
 {
     if (!$this->questionInfoShown) {
         $this->io->write(array("<comment> ! [NOTE] You can change all the configuration options later", " ! on the config.yml file in the app folder</>\n"));
         $this->questionInfoShown = true;
     }
     if (!$node->getAttribute('asked')) {
         return $node->getDefaultValue();
     }
     $this->writeWarning($node);
     if ($info = $node->getInfo()) {
         $this->io->write(" {$info}");
     }
     if ($example = $node->getExample()) {
         // We use Inline::dump() to convert the value to the YAML
         // format so that it is readable by the user (as an example,
         // false values are converted to 'false' instead of an empty
         // string)
         $example = Inline::dump($example);
         $this->io->write(" Example: <comment>{$example}</comment>");
     }
     $question = " <fg=green>{$name}";
     if ($node instanceof EnumNode) {
         // Create list of possible values for enum configuration parameters
         $values = $node->getValues();
         foreach ($values as &$value) {
             $value = Inline::dump($value);
         }
         $question .= ' (' . implode(', ', $values) . ')';
     }
     $question .= "</fg=green>";
     if ($node->hasDefaultValue()) {
         // Show the default value of the parameter
         $default = Inline::dump($node->getDefaultValue());
         $question .= " [<comment>{$default}</comment>]";
     } else {
         $default = null;
     }
     // Show a user-friendly prompt
     $question .= ":\n > ";
     $value = $this->io->askAndValidate($question, function ($value) use($node) {
         $value = Inline::parse($value);
         // Make sure that there are no errors
         $node->finalize($value);
         return $value;
     }, null, $default);
     $this->io->write("");
     return $value;
 }
開發者ID:allejo,項目名稱:bzion,代碼行數:56,代碼來源:ConfigHandler.php

示例13: parseValue

 /**
  * 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('/^' . Inline::REGEX_TAG_PATTERN . self::BLOCK_SCALAR_HEADER_PATTERN . '$/', $value, $matches)) {
         $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
         $output = $this->parseBlockScalar($matches['separator'], preg_replace('#\\d+#', '', $modifiers), (int) abs($modifiers));
         if (isset($matches['tag']) && $matches['tag'] == '!!binary') {
             $output = base64_decode($output);
         }
         return $output;
     }
     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;
     }
 }
開發者ID:johnnytemp,項目名稱:symfony,代碼行數:46,代碼來源:Parser.php

示例14: checkPermissionToInstall

 private function checkPermissionToInstall()
 {
     $value = $this->io->ask("<question>Would you like connect OrangeGate with solr ?</question> [<comment>yes</comment>] ", 'yes');
     return Inline::parse($value) === "yes" ? true : false;
 }
開發者ID:symbio,項目名稱:orangegate4-search-bundle,代碼行數:5,代碼來源:Processor.php

示例15: testParseUnquotedAsteriskFollowedByAComment

 /**
  * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  * @expectedExceptionMessage A reference must contain at least one character.
  */
 public function testParseUnquotedAsteriskFollowedByAComment()
 {
     Inline::parse('{ foo: * #foo }');
 }
開發者ID:edwardricardo,項目名稱:zenska,代碼行數:8,代碼來源:InlineTest.php


注:本文中的Symfony\Component\Yaml\Inline::parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。