-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Added pipe for multiline string (correctly indented), which makes them much more readable #17912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Multiline strings handled with correct tabs
- Loading branch information
commit 2d3b1fa84115fca5d1b0a91f2a6b969bbe014133
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding this new argument will mess up with the BC layer for the old signature currently. |
||
{ | ||
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)); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the new argument must be placed after the flags, for BC reasons