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


PHP Dumper::setIndentation方法代码示例

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


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

示例1: dump

public static function dump($array, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $objectSupport = false)
{
$yaml = new Dumper();
$yaml->setIndentation($indent);

return $yaml->dump($array, $inline, 0, $exceptionOnInvalidType, $objectSupport);
}
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:7,代码来源:Yaml.php

示例2: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state, $key = '')
 {
     // Get the old value
     $old_value = \Drupal::state()->get($key);
     // First we will show the user the content of the variable about to be edited
     $form['old_value'] = array('#type' => 'item', '#title' => t('Old value for %name', array('%name' => $key)), '#markup' => kprint_r($old_value, TRUE));
     // Store in the form the name of the state variable
     $form['state_name'] = array('#type' => 'hidden', '#value' => $key);
     // Only simple structures are allowed to be edited.
     $disabled = !$this->checkObject($old_value);
     // Set the transport format for the new value. Values:
     //  - plain
     //  - yaml
     $form['transport'] = array('#type' => 'hidden', '#value' => 'plain');
     if (is_array($old_value)) {
         $dumper = new Dumper();
         // Set Yaml\Dumper's default indentation for nested nodes/collections to
         // 2 spaces for consistency with Drupal coding standards.
         $dumper->setIndentation(2);
         // The level where you switch to inline YAML is set to PHP_INT_MAX to
         // ensure this does not occur.
         $old_value = $dumper->dump($old_value, PHP_INT_MAX);
         $form['transport']['#value'] = 'yaml';
     }
     $form['new_value'] = array('#type' => 'textarea', '#title' => t('New value'), '#default_value' => $disabled ? '' : $old_value, '#disabled' => $disabled);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
     $form['actions']['cancel'] = array('#type' => 'link', '#title' => t('Cancel'), '#href' => 'devel/state');
     return $form;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:33,代码来源:SystemStateEdit.php

示例3: getYaml

 public function getYaml($entities, $locale)
 {
     // Unflatten array
     $entitiesNested = array();
     foreach ($entities as $entity => $spec) {
         // Legacy support: Don't count *.ss as namespace
         $entity = preg_replace('/\\.ss\\./', '___ss.', $entity);
         $parts = explode('.', $entity);
         $currLevel =& $entitiesNested;
         while ($part = array_shift($parts)) {
             $part = str_replace('___ss', '.ss', $part);
             if (!isset($currLevel[$part])) {
                 $currLevel[$part] = array();
             }
             $currLevel =& $currLevel[$part];
         }
         $currLevel = $spec[0];
     }
     // Write YAML
     $dumper = new Dumper();
     $dumper->setIndentation(2);
     // TODO Dumper can't handle YAML comments, so the context information is currently discarded
     $result = $dumper->dump(array($locale => $entitiesNested), 99);
     return $result;
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:25,代码来源:i18nTextCollector_Writer_RailsYaml.php

示例4: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $config_name = '')
 {
     $data = $this->config($config_name)->get();
     if ($data === FALSE) {
         drupal_set_message(t('Config !name does not exist in the system.', array('!name' => $config_name)), 'error');
         return;
     }
     if (empty($data)) {
         drupal_set_message(t('Config !name exists but has no data.', array('!name' => $config_name)), 'warning');
         return;
     }
     $dumper = new Dumper();
     // Set Yaml\Dumper's default indentation for nested nodes/collections to
     // 2 spaces for consistency with Drupal coding standards.
     $dumper->setIndentation(2);
     // The level where you switch to inline YAML is set to PHP_INT_MAX to
     // ensure this does not occur.
     $output = $dumper->dump($data, PHP_INT_MAX);
     $form['name'] = array('#type' => 'value', '#value' => $config_name);
     $form['value'] = array('#type' => 'item', '#title' => t('Old value for %variable', array('%variable' => $config_name)), '#markup' => dpr($output, TRUE));
     $form['new'] = array('#type' => 'textarea', '#title' => t('New value'), '#default_value' => $output);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
     $form['actions']['cancel'] = array('#type' => 'link', '#title' => t('Cancel'), '#href' => 'devel/config');
     return $form;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:29,代码来源:ConfigEditor.php

示例5: dumpToString

 /**
  * @param mixed $value
  *
  * @return string
  */
 public function dumpToString($value)
 {
     $dumper = new Dumper();
     $dumper->setIndentation(2);
     $yamlString = $dumper->dump($value, 15);
     return $yamlString;
 }
开发者ID:jamescaldwell,项目名称:TestScribe,代码行数:12,代码来源:YamlUtil.php

示例6: asString

 public function asString()
 {
     $jsondom = new \FluentDOM\Serializer\Json($this->_document);
     $dumper = new Dumper();
     $dumper->setIndentation(2);
     $yaml = $dumper->dump(json_decode(json_encode($jsondom), JSON_OBJECT_AS_ARRAY), 10, 0);
     return (string) $yaml;
 }
开发者ID:fluentdom,项目名称:yaml-symfony,代码行数:8,代码来源:Serializer.php

示例7: dump

 /**
  * Dumps a PHP value to a YAML string.
  *
  * The dump method, when supplied with an array, will do its best
  * to convert the array into friendly YAML.
  *
  * @param mixed $input                  The PHP value
  * @param int   $inline                 The level where you switch to inline YAML
  * @param int   $indent                 The amount of spaces to use for indentation of nested nodes
  * @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 A YAML string representing the original PHP value
  */
 public static function dump($input, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $objectSupport = false)
 {
     if ($indent < 1) {
         throw new \InvalidArgumentException('The indentation must be greater than zero.');
     }
     $yaml = new Dumper();
     $yaml->setIndentation($indent);
     return $yaml->dump($input, $inline, 0, $exceptionOnInvalidType, $objectSupport);
 }
开发者ID:richlove1,项目名称:avc-october,代码行数:23,代码来源:Yaml.php

示例8: dump

 /**
  * Dumps a PHP array to a YAML string.
  *
  * The dump method, when supplied with an array, will do its best
  * to convert the array into friendly YAML.
  *
  * @param array $array                  PHP array
  * @param int   $inline                 The level where you switch to inline YAML
  * @param int   $indent                 The amount of spaces to use for indentation of nested nodes.
  * @param bool  $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
  * @param int   $flags                  A bit field of DUMP_* constants to customize the dumped YAML string
  *
  * @return string A YAML string representing the original PHP array
  */
 public static function dump($array, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $flags = 0)
 {
     if (is_bool($flags)) {
         @trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
         $flags = (int) $flags;
     }
     $yaml = new Dumper();
     $yaml->setIndentation($indent);
     return $yaml->dump($array, $inline, 0, $exceptionOnInvalidType, $flags);
 }
开发者ID:pakaya16,项目名称:frontendMKP,代码行数:24,代码来源:Yaml.php

示例9: encode

 /**
  * {@inheritdoc}
  */
 public static function encode($data)
 {
     try {
         $yaml = new Dumper();
         $yaml->setIndentation(2);
         return $yaml->dump($data, PHP_INT_MAX, 0, TRUE, FALSE);
     } catch (\Exception $e) {
         throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:13,代码来源:YamlSymfony.php

示例10: arrayToYaml

 public function arrayToYaml($data)
 {
     if (is_string($data)) {
         return trim($data);
     } else {
         // Convert data to YAML
         $dumper = new Dumper();
         $dumper->setIndentation(2);
         return trim($dumper->dump($data, PHP_INT_MAX));
     }
 }
开发者ID:westkingdom,项目名称:hierarchical-group-email,代码行数:11,代码来源:LegacyGroupsTest.php

示例11: getData

 public function getData()
 {
     if (TRUE === $this->getIsHierarchical()) {
         $yaml = new Dumper();
         $yaml->setIndentation(2);
         return $yaml->dump($this->_prepareHierarchicalCollection(), 5, 0, FALSE, TRUE);
     } else {
         $configSet = $this->_prepareFlatCollection();
         return $this->_generateYaml($configSet);
     }
 }
开发者ID:ktomk,项目名称:HarrisStreet-ImpEx,代码行数:11,代码来源:Yaml.php

示例12: yamlDecode

 protected static function yamlDecode($file, $aliases = [])
 {
     $code = "alias:\n";
     $aliases['path'] = dirname($file);
     $yaml = new Dumper();
     $yaml->setIndentation(2);
     foreach ($aliases as $key => $value) {
         $code .= '  - &' . $key . "\n" . $yaml->dump($value, PHP_INT_MAX, 4, TRUE, FALSE) . "\n";
     }
     return Yaml::decode($code . file_get_contents($file));
 }
开发者ID:d-f-d,项目名称:d_submodules,代码行数:11,代码来源:YamlLoader.php

示例13: export

 /**
  * Export translations in to the given file.
  *
  * @param string $file
  * @param array  $translations
  *
  * @return bool
  */
 public function export($file, $translations)
 {
     $bytes = false;
     if (pathinfo($file, PATHINFO_EXTENSION) === 'yml') {
         $ymlDumper = new Dumper();
         $ymlDumper->setIndentation(0);
         $ymlContent = '';
         $ymlContent .= $ymlDumper->dump($translations, 10);
         $bytes = file_put_contents($file, $ymlContent);
     }
     return $bytes !== false;
 }
开发者ID:ndinh215,项目名称:TranslationsBundle,代码行数:20,代码来源:YmlExport.php

示例14: generateYaml

 /**
  * Generate a YAML file from an array
  *
  * @param array  $data
  * @param string $outputFile
  *
  * @throws \InvalidArgumentException
  */
 public static function generateYaml(array $data, $outputFile)
 {
     $outputFileDir = dirname($outputFile);
     if (!is_dir($outputFileDir)) {
         throw new \InvalidArgumentException("{$outputFileDir} is not a valid directory (" . __FUNCTION__ . ')');
     }
     $dumper = new YamlDumper();
     $dumper->setIndentation(4);
     $yaml = $dumper->dump($data, 3);
     file_put_contents($outputFile, $yaml);
     return true;
 }
开发者ID:inetprocess,项目名称:sugarcli,代码行数:20,代码来源:Utils.php

示例15: export

 /**
  * {@inheritdoc}
  */
 public function export($file, $translations)
 {
     if ($this->createTree) {
         $result = $this->createMultiArray($translations);
         $translations = $this->flattenArray($result);
     }
     $ymlDumper = new Dumper();
     $ymlDumper->setIndentation(2);
     $ymlContent = $ymlDumper->dump($translations, 10);
     $bytes = file_put_contents($file, $ymlContent);
     return $bytes !== false;
 }
开发者ID:StuartApp,项目名称:LexikTranslationBundle,代码行数:15,代码来源:YamlExporter.php


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