本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
示例5: dumpToString
/**
* @param mixed $value
*
* @return string
*/
public function dumpToString($value)
{
$dumper = new Dumper();
$dumper->setIndentation(2);
$yamlString = $dumper->dump($value, 15);
return $yamlString;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
示例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));
}
}
示例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);
}
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}