本文整理汇总了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;
}
示例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');
}
}
示例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);
}));
}
示例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;
}
}
示例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;
}
示例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}');
}
示例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));
}
示例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;
}
}
示例9: testParseInvalidBinaryData
/**
* @dataProvider getInvalidBinaryData
*/
public function testParseInvalidBinaryData($data, $expectedMessage)
{
$this->setExpectedExceptionRegExp('\\Symfony\\Component\\Yaml\\Exception\\ParseException', $expectedMessage);
Inline::parse($data);
}
示例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;
}
}
示例11: testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF
public function testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF()
{
$value = '686e444';
$this->assertSame($value, Inline::parse(Inline::dump($value)));
}
示例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;
}
示例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;
}
}
示例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;
}
示例15: testParseUnquotedAsteriskFollowedByAComment
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage A reference must contain at least one character.
*/
public function testParseUnquotedAsteriskFollowedByAComment()
{
Inline::parse('{ foo: * #foo }');
}