From 2d3b1fa84115fca5d1b0a91f2a6b969bbe014133 Mon Sep 17 00:00:00 2001 From: Tony Mobily Date: Wed, 24 Feb 2016 14:01:12 +0800 Subject: [PATCH 1/4] Multiline strings handled with correct tabs --- src/Symfony/Component/Yaml/Dumper.php | 9 +++++---- src/Symfony/Component/Yaml/Inline.php | 19 ++++++++++++++----- src/Symfony/Component/Yaml/Yaml.php | 5 +++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/Yaml/Dumper.php b/src/Symfony/Component/Yaml/Dumper.php index 6516e4cb22d6a..61f0458c0560a 100644 --- a/src/Symfony/Component/Yaml/Dumper.php +++ b/src/Symfony/Component/Yaml/Dumper.php @@ -55,7 +55,7 @@ public function setIndentation($num) * * @return string The YAML representation of the PHP value */ - public function dump($input, $inline = 0, $indent = 0, $flags = 0) + public function dump($input, $inline = 0, $indent = 0, $absIndent = 0, $flags = 0) { if (is_bool($flags)) { @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); @@ -79,7 +79,7 @@ public function dump($input, $inline = 0, $indent = 0, $flags = 0) $prefix = $indent ? str_repeat(' ', $indent) : ''; if ($inline <= 0 || !is_array($input) || empty($input)) { - $output .= $prefix.Inline::dump($input, $flags); + $output .= $prefix.Inline::dump($input, $flags, $absIndent); } else { $isAHash = array_keys($input) !== range(0, count($input) - 1); @@ -88,9 +88,10 @@ public function dump($input, $inline = 0, $indent = 0, $flags = 0) $output .= sprintf('%s%s%s%s', $prefix, - $isAHash ? Inline::dump($key, $flags).':' : '-', + $isAHash ? Inline::dump($key, $flags, $absIndent).':' : '-', $willBeInlined ? ' ' : "\n", - $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $flags) + $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $inline - 1 <= 0 ? 0 : $absIndent + $this->indentation, $flags) + ).($willBeInlined ? "\n" : ''); } } diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index b11e03147cd75..b5afbe55c967b 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -125,7 +125,7 @@ public static function parse($value, $flags = 0, $references = array()) * * @throws DumpException When trying to dump PHP resource */ - public static function dump($value, $flags = 0) + public static function dump($value, $flags = 0, $indent = 0) { if (is_bool($flags)) { @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); @@ -165,7 +165,7 @@ public static function dump($value, $flags = 0) return 'null'; case is_array($value): - return self::dumpArray($value, $flags); + return self::dumpArray($value, $flags, $indent); case null === $value: return 'null'; case true === $value: @@ -197,6 +197,15 @@ public static function dump($value, $flags = 0) return $repr; case '' == $value: return "''"; + case strstr($value, "\n"): + if (Yaml::DUMP_MULTI_LINE_AS_BLOCK & $flags) { + if ($indent) { + $prefix = $indent ? str_repeat(' ', $indent) : ''; + return "|\n$prefix". preg_replace( '/\n/',"\n$prefix", str_replace( "\r", '', $value ) ); + } + } + + case Escaper::requiresDoubleQuoting($value): return Escaper::escapeWithDoubleQuotes($value); case Escaper::requiresSingleQuoting($value): @@ -216,7 +225,7 @@ public static function dump($value, $flags = 0) * * @return string The YAML string representing the PHP array */ - private static function dumpArray($value, $flags) + private static function dumpArray($value, $flags, $indent) { // array $keys = array_keys($value); @@ -226,7 +235,7 @@ private static function dumpArray($value, $flags) ) { $output = array(); foreach ($value as $val) { - $output[] = self::dump($val, $flags); + $output[] = self::dump($val, $flags, $indent); } return sprintf('[%s]', implode(', ', $output)); @@ -235,7 +244,7 @@ private static function dumpArray($value, $flags) // mapping $output = array(); foreach ($value as $key => $val) { - $output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags)); + $output[] = sprintf('%s: %s', self::dump($key, $flags, $indent), self::dump($val, $flags, $indent)); } return sprintf('{ %s }', implode(', ', $output)); diff --git a/src/Symfony/Component/Yaml/Yaml.php b/src/Symfony/Component/Yaml/Yaml.php index 9c321a81322e1..fbf62c607e01d 100644 --- a/src/Symfony/Component/Yaml/Yaml.php +++ b/src/Symfony/Component/Yaml/Yaml.php @@ -26,6 +26,7 @@ class Yaml const PARSE_OBJECT_FOR_MAP = 8; const DUMP_EXCEPTION_ON_INVALID_TYPE = 16; const PARSE_DATETIME = 32; + const DUMP_MULTI_LINE_AS_BLOCK = 64; /** * Parses YAML into a PHP value. @@ -89,7 +90,7 @@ public static function parse($input, $flags = 0) * * @return string A YAML string representing the original PHP array */ - public static function dump($array, $inline = 2, $indent = 4, $flags = 0) + public static function dump($array, $inline = 2, $indent = 4, $absInden = 0,$flags = 0) { if (is_bool($flags)) { @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); @@ -111,6 +112,6 @@ public static function dump($array, $inline = 2, $indent = 4, $flags = 0) $yaml = new Dumper($indent); - return $yaml->dump($array, $inline, 0, $flags); + return $yaml->dump($array, $inline, 0, 0, $flags); } } From dfb21a672a26447446c25e4082a1b17699ea1f34 Mon Sep 17 00:00:00 2001 From: Tony Mobily Date: Wed, 24 Feb 2016 14:03:21 +0800 Subject: [PATCH 2/4] Missing semicolon added --- src/Symfony/Component/Yaml/Yaml.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Yaml/Yaml.php b/src/Symfony/Component/Yaml/Yaml.php index fbf62c607e01d..d65dee9facac3 100644 --- a/src/Symfony/Component/Yaml/Yaml.php +++ b/src/Symfony/Component/Yaml/Yaml.php @@ -90,7 +90,7 @@ public static function parse($input, $flags = 0) * * @return string A YAML string representing the original PHP array */ - public static function dump($array, $inline = 2, $indent = 4, $absInden = 0,$flags = 0) + public static function dump($array, $inline = 2, $indent = 4, $absIndent = 0,$flags = 0) { if (is_bool($flags)) { @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); From db84e15525a4b72707e3d37b2f0df3f7dc3fd906 Mon Sep 17 00:00:00 2001 From: Tony Mobily Date: Wed, 24 Feb 2016 14:10:33 +0800 Subject: [PATCH 3/4] Coding standard --- src/Symfony/Component/Yaml/Inline.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index b5afbe55c967b..3227f505cc64e 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -201,11 +201,10 @@ public static function dump($value, $flags = 0, $indent = 0) if (Yaml::DUMP_MULTI_LINE_AS_BLOCK & $flags) { if ($indent) { $prefix = $indent ? str_repeat(' ', $indent) : ''; - return "|\n$prefix". preg_replace( '/\n/',"\n$prefix", str_replace( "\r", '', $value ) ); + return "|\n$prefix".preg_replace( '/\n/',"\n$prefix", str_replace( "\r", '', $value ) ); } } - case Escaper::requiresDoubleQuoting($value): return Escaper::escapeWithDoubleQuotes($value); case Escaper::requiresSingleQuoting($value): From 2de3aeebbdcb4dcab99262918140994639f8023f Mon Sep 17 00:00:00 2001 From: Tony Mobily Date: Wed, 24 Feb 2016 14:11:39 +0800 Subject: [PATCH 4/4] More coding tandards --- src/Symfony/Component/Yaml/Inline.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 3227f505cc64e..fbee784a5cb86 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -201,6 +201,7 @@ public static function dump($value, $flags = 0, $indent = 0) if (Yaml::DUMP_MULTI_LINE_AS_BLOCK & $flags) { if ($indent) { $prefix = $indent ? str_repeat(' ', $indent) : ''; + return "|\n$prefix".preg_replace( '/\n/',"\n$prefix", str_replace( "\r", '', $value ) ); } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy