当前位置: 首页>>代码示例>>PHP>>正文


PHP Inline::dump方法代码示例

本文整理汇总了PHP中Symfony\Component\Yaml\Inline::dump方法的典型用法代码示例。如果您正苦于以下问题:PHP Inline::dump方法的具体用法?PHP Inline::dump怎么用?PHP Inline::dump使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Yaml\Inline的用法示例。


在下文中一共展示了Inline::dump方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: dump

 /**
  * Dumps a PHP value to YAML.
  *
  * @param mixed $input                  The PHP value
  * @param int   $inline                 The level where you switch to inline YAML
  * @param int   $indent                 The level of indentation (used internally)
  * @param bool  $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
  * @param bool  $objectSupport          true if object support is enabled, false otherwise
  *
  * @return string The YAML representation of the PHP value
  */
 public function dump($input, $inline = 0, $indent = 0, $exceptionOnInvalidType = false, $objectSupport = false)
 {
     $output = '';
     $prefix = $indent ? str_repeat(' ', $indent) : '';
     if ($inline <= 0 || !is_array($input) || empty($input)) {
         $output .= $prefix . Inline::dump($input, $exceptionOnInvalidType, $objectSupport);
     } else {
         $isAHash = array_keys($input) !== range(0, count($input) - 1);
         foreach ($input as $key => $value) {
             $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
             $output .= sprintf('%s%s%s%s', $prefix, $isAHash ? Inline::dump($key, $exceptionOnInvalidType, $objectSupport) . ':' : '-', $willBeInlined ? ' ' : "\n", $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $exceptionOnInvalidType, $objectSupport)) . ($willBeInlined ? "\n" : '');
         }
     }
     return str_replace("'''", "'", $output);
 }
开发者ID:TMSolution,项目名称:PrototypeBundle,代码行数:26,代码来源:Dumper.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->getTestsForLoad() as $yaml => $value) {
         if ($value == 1230) {
             continue;
         }
         $this->assertEquals($value, Inline::load(Inline::dump($value)), 'check consistency');
     }
     foreach ($testsForDump as $yaml => $value) {
         if ($value == 1230) {
             continue;
         }
         $this->assertEquals($value, Inline::load(Inline::dump($value)), 'check consistency');
     }
 }
开发者ID:rooster,项目名称:symfony,代码行数:19,代码来源:InlineTest.php

示例3: dump

 /**
  * Dumps a PHP value to YAML.
  *
  * @param  mixed   $input  The PHP value
  * @param  integer $inline The level where you switch to inline YAML
  * @param  integer $indent The level of indentation (used internally)
  *
  * @return string  The YAML representation of the PHP value
  */
 public function dump($input, $inline = 0, $indent = 0)
 {
     $output = '';
     $prefix = $indent ? str_repeat(' ', $indent) : '';
     if ($inline <= 0 || !is_array($input) || empty($input)) {
         $output .= $prefix . Inline::dump($input);
     } else {
         $isAHash = array_keys($input) !== range(0, count($input) - 1);
         if ($isAHash) {
             foreach ($input as $key => $value) {
                 $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
                 $output .= sprintf('%s%s%s%s', $prefix, $isAHash ? Inline::dump($key) . ':' : '-', $willBeInlined ? ' ' : "\n", $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + 4)) . ($willBeInlined ? "\n" : '');
             }
         } else {
             foreach ($input as $key => $value) {
                 $output .= sprintf('%s%s%s%s', $prefix, '- ', Inline::dump($value), "\n");
             }
         }
     }
     return $output;
 }
开发者ID:ldnok,项目名称:GeneratorBundle,代码行数:30,代码来源:Dumper.php

示例4: dumpStructureRecursively

 private function dumpStructureRecursively(array $structure)
 {
     $isFirst = true;
     $precededByMessage = false;
     foreach ($structure as $k => $v) {
         if ($isMessage = $v instanceof Message) {
             $desc = $v->getDesc();
             $meaning = $v->getMeaning();
             if (!$isFirst && (!$precededByMessage || $desc || $meaning)) {
                 $this->writer->write("\n");
             }
             if ($desc) {
                 $desc = str_replace(array("\r\n", "\n", "\r", "\t"), array('\\r\\n', '\\n', '\\r', '\\t'), $desc);
                 $this->writer->writeln('# Desc: ' . $desc);
             }
             if ($meaning) {
                 $this->writer->writeln('# Meaning: ' . $meaning);
             }
         } else {
             if (!$isFirst) {
                 $this->writer->write("\n");
             }
         }
         $isFirst = false;
         $precededByMessage = $isMessage;
         $this->writer->write(Inline::dump($k) . ':');
         if ($isMessage) {
             $this->writer->write(' ' . Inline::dump($v->getLocaleString()));
             if ($v->isNew()) {
                 $this->writer->write('   # FIXME');
             }
             $this->writer->write("\n");
             continue;
         }
         $this->writer->write("\n")->indent();
         $this->dumpStructureRecursively($v);
         $this->writer->outdent();
     }
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:39,代码来源:YamlDumper.php

示例5: serialize

 public function serialize(VisitorInterface $visitor, $data, $type, &$visited)
 {
     if (!$data instanceof \DateTime) {
         return;
     }
     if ($visitor instanceof XmlSerializationVisitor) {
         if (null === $visitor->document) {
             $visitor->document = $visitor->createDocument(null, null, true);
         }
         $visited = true;
         return $visitor->document->createTextNode($data->format($this->format));
     } else {
         if ($visitor instanceof GenericSerializationVisitor) {
             $visited = true;
             return $data->format($this->format);
         } else {
             if ($visitor instanceof YamlSerializationVisitor) {
                 $visited = true;
                 return Inline::dump($data->format($this->format));
             }
         }
     }
 }
开发者ID:hykz,项目名称:Depot,代码行数:23,代码来源:DateTimeHandler.php

示例6: testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF

 public function testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF()
 {
     $value = '686e444';
     $this->assertSame($value, Inline::parse(Inline::dump($value)));
 }
开发者ID:senthil-r-wiredelta,项目名称:meilleure-visite,代码行数:5,代码来源:InlineTest.php

示例7: visitProperty

 public function visitProperty(PropertyMetadata $metadata, $data)
 {
     $v = null === $metadata->getter ? $metadata->reflection->getValue($data) : $data->{$metadata->getter}();
     if (null === $v) {
         return;
     }
     $name = $this->namingStrategy->translateName($metadata);
     $this->writer->writeln(Inline::dump($name) . ':')->indent();
     $this->setCurrentMetadata($metadata);
     $count = $this->writer->changeCount;
     if (null !== ($v = $this->navigator->accept($v, null, $this))) {
         $this->writer->rtrim(false)->writeln(' ' . $v);
     } else {
         if ($count === $this->writer->changeCount) {
             $this->writer->revert();
         }
     }
     $this->writer->outdent();
     $this->revertCurrentMetadata();
 }
开发者ID:richsage,项目名称:JMSSerializerBundle,代码行数:20,代码来源:YamlSerializationVisitor.php

示例8: writeNode

 /**
  * @param NodeInterface $node
  * @param int           $depth
  * @param bool          $prototypedArray
  */
 private function writeNode(NodeInterface $node, $depth = 0, $prototypedArray = false)
 {
     $comments = array();
     $default = '';
     $defaultArray = null;
     $children = null;
     $example = $node->getExample();
     // defaults
     if ($node instanceof ArrayNode) {
         $children = $node->getChildren();
         if ($node instanceof PrototypedArrayNode) {
             $children = $this->getPrototypeChildren($node);
         }
         if (!$children) {
             if ($node->hasDefaultValue() && count($defaultArray = $node->getDefaultValue())) {
                 $default = '';
             } elseif (!is_array($example)) {
                 $default = '[]';
             }
         }
     } elseif ($node instanceof EnumNode) {
         $comments[] = 'One of ' . implode('; ', array_map('json_encode', $node->getValues()));
         $default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
     } else {
         $default = '~';
         if ($node->hasDefaultValue()) {
             $default = $node->getDefaultValue();
             if (is_array($default)) {
                 if (count($defaultArray = $node->getDefaultValue())) {
                     $default = '';
                 } elseif (!is_array($example)) {
                     $default = '[]';
                 }
             } else {
                 $default = Inline::dump($default);
             }
         }
     }
     // required?
     if ($node->isRequired()) {
         $comments[] = 'Required';
     }
     // example
     if ($example && !is_array($example)) {
         $comments[] = 'Example: ' . $example;
     }
     $default = (string) $default != '' ? ' ' . $default : '';
     $comments = count($comments) ? '# ' . implode(', ', $comments) : '';
     $key = $prototypedArray ? '-' : $node->getName() . ':';
     $text = rtrim(sprintf('%-21s%s %s', $key, $default, $comments), ' ');
     if ($info = $node->getInfo()) {
         $this->writeLine('');
         // indenting multi-line info
         $info = str_replace("\n", sprintf("\n%" . $depth * 4 . 's# ', ' '), $info);
         $this->writeLine('# ' . $info, $depth * 4);
     }
     $this->writeLine($text, $depth * 4);
     // output defaults
     if ($defaultArray) {
         $this->writeLine('');
         $message = count($defaultArray) > 1 ? 'Defaults' : 'Default';
         $this->writeLine('# ' . $message . ':', $depth * 4 + 4);
         $this->writeArray($defaultArray, $depth + 1);
     }
     if (is_array($example)) {
         $this->writeLine('');
         $message = count($example) > 1 ? 'Examples' : 'Example';
         $this->writeLine('# ' . $message . ':', $depth * 4 + 4);
         $this->writeArray($example, $depth + 1);
     }
     if ($children) {
         foreach ($children as $childNode) {
             $this->writeNode($childNode, $depth + 1, $node instanceof PrototypedArrayNode && !$node->getKeyAttribute());
         }
     }
 }
开发者ID:symfony,项目名称:symfony,代码行数:81,代码来源:YamlReferenceDumper.php

示例9: testDumpDateTime

 /**
  * @dataProvider getDateTimeDumpTests
  */
 public function testDumpDateTime($dateTime, $expected)
 {
     $this->assertSame($expected, Inline::dump($dateTime));
 }
开发者ID:natmchugh,项目名称:symfony,代码行数:7,代码来源:InlineTest.php

示例10: visitProperty

 public function visitProperty(PropertyMetadata $metadata, $data, Context $context)
 {
     $v = $metadata->getValue($data);
     if (null === $v && !$context->shouldSerializeNull()) {
         return;
     }
     $name = $this->namingStrategy->translateName($metadata);
     if (!$metadata->inline) {
         $this->writer->writeln(Inline::dump($name) . ':')->indent();
     }
     $this->setCurrentMetadata($metadata);
     $count = $this->writer->changeCount;
     if (null !== ($v = $this->navigator->accept($v, $metadata->type, $context))) {
         $this->writer->rtrim(false)->writeln(' ' . $v);
     } elseif ($count === $this->writer->changeCount && !$metadata->inline) {
         $this->writer->revert();
     }
     if (!$metadata->inline) {
         $this->writer->outdent();
     }
     $this->revertCurrentMetadata();
 }
开发者ID:dgamo,项目名称:serializer,代码行数:22,代码来源:YamlSerializationVisitor.php

示例11: 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

示例12: serialize

 public function serialize(VisitorInterface $visitor, $data, $type, &$visited)
 {
     if (!$data instanceof Article) {
         return;
     }
     if ($visitor instanceof XmlSerializationVisitor) {
         $visited = true;
         if (null === $visitor->document) {
             $visitor->document = $visitor->createDocument(null, null, false);
         }
         $visitor->document->appendChild($visitor->document->createElement($this->element, $this->value));
     } elseif ($visitor instanceof JsonSerializationVisitor) {
         $visited = true;
         $visitor->setRoot(array($this->element => $this->value));
     } elseif ($visitor instanceof YamlSerializationVisitor) {
         $visited = true;
         $visitor->writer->writeln(Inline::dump($this->element) . ': ' . Inline::dump($this->value));
     }
 }
开发者ID:rosstuck,项目名称:JMSSerializerBundle,代码行数:19,代码来源:BaseSerializationTest.php

示例13: writeNode

 /**
  * @param NodeInterface $node
  * @param int           $depth
  */
 private function writeNode(NodeInterface $node, $depth = 0)
 {
     $comments = array();
     $default = '';
     $defaultArray = null;
     $children = null;
     $example = $node->getExample();
     // defaults
     if ($node instanceof ArrayNode) {
         $children = $node->getChildren();
         if ($node instanceof PrototypedArrayNode) {
             $prototype = $node->getPrototype();
             if ($prototype instanceof ArrayNode) {
                 $children = $prototype->getChildren();
             }
             // check for attribute as key
             if ($key = $node->getKeyAttribute()) {
                 $keyNodeClass = 'Symfony\\Component\\Config\\Definition\\' . ($prototype instanceof ArrayNode ? 'ArrayNode' : 'ScalarNode');
                 $keyNode = new $keyNodeClass($key, $node);
                 $keyNode->setInfo('Prototype');
                 // add children
                 foreach ($children as $childNode) {
                     $keyNode->addChild($childNode);
                 }
                 $children = array($key => $keyNode);
             }
         }
         if (!$children) {
             if ($node->hasDefaultValue() && count($defaultArray = $node->getDefaultValue())) {
                 $default = '';
             } elseif (!is_array($example)) {
                 $default = '[]';
             }
         }
     } elseif ($node instanceof EnumNode) {
         $comments[] = 'One of ' . implode('; ', array_map('json_encode', $node->getValues()));
         $default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
     } else {
         $default = '~';
         if ($node->hasDefaultValue()) {
             $default = $node->getDefaultValue();
             if (is_array($default)) {
                 if (count($defaultArray = $node->getDefaultValue())) {
                     $default = '';
                 } elseif (!is_array($example)) {
                     $default = '[]';
                 }
             } else {
                 $default = Inline::dump($default);
             }
         }
     }
     // required?
     if ($node->isRequired()) {
         $comments[] = 'Required';
     }
     // example
     if ($example && !is_array($example)) {
         $comments[] = 'Example: ' . $example;
     }
     $default = (string) $default != '' ? ' ' . $default : '';
     $comments = count($comments) ? '# ' . implode(', ', $comments) : '';
     $text = rtrim(sprintf('%-20s %s %s', $node->getName() . ':', $default, $comments), ' ');
     if ($info = $node->getInfo()) {
         $this->writeLine('');
         // indenting multi-line info
         $info = str_replace("\n", sprintf("\n%" . $depth * 4 . 's# ', ' '), $info);
         $this->writeLine('# ' . $info, $depth * 4);
     }
     $this->writeLine($text, $depth * 4);
     // output defaults
     if ($defaultArray) {
         $this->writeLine('');
         $message = count($defaultArray) > 1 ? 'Defaults' : 'Weather';
         $this->writeLine('# ' . $message . ':', $depth * 4 + 4);
         $this->writeArray($defaultArray, $depth + 1);
     }
     if (is_array($example)) {
         $this->writeLine('');
         $message = count($example) > 1 ? 'Examples' : 'Example';
         $this->writeLine('# ' . $message . ':', $depth * 4 + 4);
         $this->writeArray($example, $depth + 1);
     }
     if ($children) {
         foreach ($children as $childNode) {
             $this->writeNode($childNode, $depth + 1);
         }
     }
 }
开发者ID:rolas123,项目名称:weather-homework,代码行数:93,代码来源:YamlReferenceDumper.php

示例14: getParams

 private function getParams(array $expectedParams, array $actualParams, array $config)
 {
     // Simply use the expectedParams value as default for the missing params.
     if (!$this->io->isInteractive()) {
         return array_replace($expectedParams, $actualParams);
     }
     $isStarted = false;
     $endpointName = $this->io->ask("<question>Please provide name of new endpoint</question> [<comment>core1</comment>]", 'core1');
     $this->setEndpointName($endpointName);
     $actualParams[$endpointName] = array();
     foreach ($expectedParams['core1'] as $key => $message) {
         if (array_key_exists($key, $actualParams[$endpointName])) {
             continue;
         }
         if (!$isStarted) {
             $isStarted = true;
             $this->io->write('<comment>Some parameters are missing. Please provide them.</comment>');
         }
         $default = Inline::dump($message);
         if ($key === "core") {
             $this->io->write('<comment>Please provide the name of core. It should be the name of your project.</comment>');
         }
         $value = $this->io->ask(sprintf('<question>%s</question> (<comment>%s</comment>): ', $key, $default), $default);
         $actualParams[$endpointName][$key] = Inline::parse($value);
     }
     return $actualParams;
 }
开发者ID:symbio,项目名称:orangegate4-search-bundle,代码行数:27,代码来源:Processor.php

示例15: serializeToYml

 /** @HandlerCallback("yml", direction = "serialization") */
 public function serializeToYml(YamlSerializationVisitor $visitor)
 {
     $visitor->writer->writeln(Inline::dump($this->element) . ': ' . Inline::dump($this->value));
 }
开发者ID:AgnaldoJaws,项目名称:TesteSocialBase,代码行数:5,代码来源:Article.php


注:本文中的Symfony\Component\Yaml\Inline::dump方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。