| 1: | <?php | 
| 2: |  | 
| 3: |  | 
| 4: |  | 
| 5: |  | 
| 6: |  | 
| 7: |  | 
| 8: |  | 
| 9: |  | 
| 10: |  | 
| 11: |  | 
| 12: | namespace Symfony\Component\Yaml; | 
| 13: |  | 
| 14: |  | 
| 15: |  | 
| 16: |  | 
| 17: |  | 
| 18: |  | 
| 19: | class Dumper | 
| 20: | { | 
| 21: |  | 
| 22: |  | 
| 23: |  | 
| 24: |  | 
| 25: |  | 
| 26: | protected $indentation = 4; | 
| 27: |  | 
| 28: |  | 
| 29: |  | 
| 30: |  | 
| 31: |  | 
| 32: |  | 
| 33: | public function setIndentation($num) | 
| 34: | { | 
| 35: | if ($num < 1) { | 
| 36: | throw new \InvalidArgumentException('The indentation must be greater than zero.'); | 
| 37: | } | 
| 38: |  | 
| 39: | $this->indentation = (int) $num; | 
| 40: | } | 
| 41: |  | 
| 42: |  | 
| 43: |  | 
| 44: |  | 
| 45: |  | 
| 46: |  | 
| 47: |  | 
| 48: |  | 
| 49: |  | 
| 50: |  | 
| 51: |  | 
| 52: |  | 
| 53: | public function dump($input, $inline = 0, $indent = 0, $exceptionOnInvalidType = false, $objectSupport = false) | 
| 54: | { | 
| 55: | $output = ''; | 
| 56: | $prefix = $indent ? str_repeat(' ', $indent) : ''; | 
| 57: |  | 
| 58: | if ($inline <= 0 || !\is_array($input) || empty($input)) { | 
| 59: | $output .= $prefix.Inline::dump($input, $exceptionOnInvalidType, $objectSupport); | 
| 60: | } else { | 
| 61: | $isAHash = Inline::isHash($input); | 
| 62: |  | 
| 63: | foreach ($input as $key => $value) { | 
| 64: | $willBeInlined = $inline - 1 <= 0 || !\is_array($value) || empty($value); | 
| 65: |  | 
| 66: | $output .= sprintf('%s%s%s%s', | 
| 67: | $prefix, | 
| 68: | $isAHash ? Inline::dump($key, $exceptionOnInvalidType, $objectSupport).':' : '-', | 
| 69: | $willBeInlined ? ' ' : "\n", | 
| 70: | $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $exceptionOnInvalidType, $objectSupport) | 
| 71: | ).($willBeInlined ? "\n" : ''); | 
| 72: | } | 
| 73: | } | 
| 74: |  | 
| 75: | return $output; | 
| 76: | } | 
| 77: | } | 
| 78: |  |