TreeStyle.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Helper;
  11. /**
  12. * Configures the output of the Tree helper.
  13. *
  14. * @author Simon André <smn.andre@gmail.com>
  15. */
  16. final class TreeStyle
  17. {
  18. public function __construct(
  19. private readonly string $prefixEndHasNext,
  20. private readonly string $prefixEndLast,
  21. private readonly string $prefixLeft,
  22. private readonly string $prefixMidHasNext,
  23. private readonly string $prefixMidLast,
  24. private readonly string $prefixRight,
  25. ) {
  26. }
  27. public static function box(): self
  28. {
  29. return new self('┃╸ ', '┗╸ ', '', '┃ ', ' ', '');
  30. }
  31. public static function boxDouble(): self
  32. {
  33. return new self('╠═ ', '╚═ ', '', '║ ', ' ', '');
  34. }
  35. public static function compact(): self
  36. {
  37. return new self('├ ', '└ ', '', '│ ', ' ', '');
  38. }
  39. public static function default(): self
  40. {
  41. return new self('├── ', '└── ', '', '│ ', ' ', '');
  42. }
  43. public static function light(): self
  44. {
  45. return new self('|-- ', '`-- ', '', '| ', ' ', '');
  46. }
  47. public static function minimal(): self
  48. {
  49. return new self('. ', '. ', '', '. ', ' ', '');
  50. }
  51. public static function rounded(): self
  52. {
  53. return new self('├─ ', '╰─ ', '', '│ ', ' ', '');
  54. }
  55. /**
  56. * @internal
  57. */
  58. public function applyPrefixes(\RecursiveTreeIterator $iterator): void
  59. {
  60. $iterator->setPrefixPart(\RecursiveTreeIterator::PREFIX_LEFT, $this->prefixLeft);
  61. $iterator->setPrefixPart(\RecursiveTreeIterator::PREFIX_MID_HAS_NEXT, $this->prefixMidHasNext);
  62. $iterator->setPrefixPart(\RecursiveTreeIterator::PREFIX_MID_LAST, $this->prefixMidLast);
  63. $iterator->setPrefixPart(\RecursiveTreeIterator::PREFIX_END_HAS_NEXT, $this->prefixEndHasNext);
  64. $iterator->setPrefixPart(\RecursiveTreeIterator::PREFIX_END_LAST, $this->prefixEndLast);
  65. $iterator->setPrefixPart(\RecursiveTreeIterator::PREFIX_RIGHT, $this->prefixRight);
  66. }
  67. }