Heimdall/vendor/symfony/console/Helper/TableStyle.php

377 lines
12 KiB
PHP
Raw Normal View History

2018-02-01 20:01:12 +00:00
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Helper;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\LogicException;
/**
* Defines the styles for a Table.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Саша Стаменковић <umpirsky@gmail.com>
* @author Dany Maillard <danymaillard93b@gmail.com>
2018-02-01 20:01:12 +00:00
*/
class TableStyle
{
private $paddingChar = ' ';
private $horizontalOutsideBorderChar = '-';
private $horizontalInsideBorderChar = '-';
private $verticalOutsideBorderChar = '|';
private $verticalInsideBorderChar = '|';
2018-02-01 20:01:12 +00:00
private $crossingChar = '+';
private $crossingTopRightChar = '+';
private $crossingTopMidChar = '+';
private $crossingTopLeftChar = '+';
private $crossingMidRightChar = '+';
private $crossingBottomRightChar = '+';
private $crossingBottomMidChar = '+';
private $crossingBottomLeftChar = '+';
private $crossingMidLeftChar = '+';
private $crossingTopLeftBottomChar = '+';
private $crossingTopMidBottomChar = '+';
private $crossingTopRightBottomChar = '+';
2019-01-18 18:33:28 +00:00
private $headerTitleFormat = '<fg=black;bg=white;options=bold> %s </>';
private $footerTitleFormat = '<fg=black;bg=white;options=bold> %s </>';
2018-02-01 20:01:12 +00:00
private $cellHeaderFormat = '<info>%s</info>';
private $cellRowFormat = '%s';
private $cellRowContentFormat = ' %s ';
private $borderFormat = '%s';
2022-03-10 11:54:29 +00:00
private $padType = \STR_PAD_RIGHT;
2018-02-01 20:01:12 +00:00
/**
* Sets padding character, used for cell padding.
*
* @return $this
*/
2022-03-10 11:54:29 +00:00
public function setPaddingChar(string $paddingChar)
2018-02-01 20:01:12 +00:00
{
if (!$paddingChar) {
2022-03-10 11:54:29 +00:00
throw new LogicException('The padding char must not be empty.');
2018-02-01 20:01:12 +00:00
}
$this->paddingChar = $paddingChar;
return $this;
}
/**
* Gets padding character, used for cell padding.
*
* @return string
*/
public function getPaddingChar()
{
return $this->paddingChar;
}
/**
* Sets horizontal border characters.
*
* <code>
* ╔═══════════════╤══════════════════════════╤══════════════════╗
* 1 ISBN 2 Title Author
* ╠═══════════════╪══════════════════════════╪══════════════════╣
* 99921-58-10-7 Divine Comedy Dante Alighieri
* 9971-5-0210-0 A Tale of Two Cities Charles Dickens
* 960-425-059-0 The Lord of the Rings J. R. R. Tolkien
* 80-902734-1-6 And Then There Were None Agatha Christie
* ╚═══════════════╧══════════════════════════╧══════════════════╝
* </code>
*
2022-03-10 11:54:29 +00:00
* @return $this
*/
public function setHorizontalBorderChars(string $outside, string $inside = null): self
{
$this->horizontalOutsideBorderChar = $outside;
$this->horizontalInsideBorderChar = $inside ?? $outside;
return $this;
}
/**
* Sets vertical border characters.
*
* <code>
* ╔═══════════════╤══════════════════════════╤══════════════════╗
* ISBN Title Author
* ╠═══════1═══════╪══════════════════════════╪══════════════════╣
* 99921-58-10-7 Divine Comedy Dante Alighieri
* 9971-5-0210-0 A Tale of Two Cities Charles Dickens
* ╟───────2───────┼──────────────────────────┼──────────────────╢
* 960-425-059-0 The Lord of the Rings J. R. R. Tolkien
* 80-902734-1-6 And Then There Were None Agatha Christie
* ╚═══════════════╧══════════════════════════╧══════════════════╝
* </code>
*
2022-03-10 11:54:29 +00:00
* @return $this
*/
public function setVerticalBorderChars(string $outside, string $inside = null): self
{
$this->verticalOutsideBorderChar = $outside;
$this->verticalInsideBorderChar = $inside ?? $outside;
return $this;
2018-02-01 20:01:12 +00:00
}
/**
* Gets border characters.
*
* @internal
*/
2022-03-10 11:54:29 +00:00
public function getBorderChars(): array
{
2019-06-11 11:29:32 +00:00
return [
$this->horizontalOutsideBorderChar,
$this->verticalOutsideBorderChar,
$this->horizontalInsideBorderChar,
$this->verticalInsideBorderChar,
2019-06-11 11:29:32 +00:00
];
}
/**
* Sets crossing characters.
*
* Example:
* <code>
* 1═══════════════2══════════════════════════2══════════════════3
* ISBN Title Author
* 8'══════════════0'═════════════════════════0'═════════════════4'
* 99921-58-10-7 Divine Comedy Dante Alighieri
* 9971-5-0210-0 A Tale of Two Cities Charles Dickens
* 8───────────────0──────────────────────────0──────────────────4
* 960-425-059-0 The Lord of the Rings J. R. R. Tolkien
* 80-902734-1-6 And Then There Were None Agatha Christie
* 7═══════════════6══════════════════════════6══════════════════5
* </code>
*
* @param string $cross Crossing char (see #0 of example)
* @param string $topLeft Top left char (see #1 of example)
* @param string $topMid Top mid char (see #2 of example)
* @param string $topRight Top right char (see #3 of example)
* @param string $midRight Mid right char (see #4 of example)
* @param string $bottomRight Bottom right char (see #5 of example)
* @param string $bottomMid Bottom mid char (see #6 of example)
* @param string $bottomLeft Bottom left char (see #7 of example)
* @param string $midLeft Mid left char (see #8 of example)
* @param string|null $topLeftBottom Top left bottom char (see #8' of example), equals to $midLeft if null
* @param string|null $topMidBottom Top mid bottom char (see #0' of example), equals to $cross if null
* @param string|null $topRightBottom Top right bottom char (see #4' of example), equals to $midRight if null
2022-03-10 11:54:29 +00:00
*
* @return $this
*/
public function setCrossingChars(string $cross, string $topLeft, string $topMid, string $topRight, string $midRight, string $bottomRight, string $bottomMid, string $bottomLeft, string $midLeft, string $topLeftBottom = null, string $topMidBottom = null, string $topRightBottom = null): self
{
$this->crossingChar = $cross;
$this->crossingTopLeftChar = $topLeft;
$this->crossingTopMidChar = $topMid;
$this->crossingTopRightChar = $topRight;
$this->crossingMidRightChar = $midRight;
$this->crossingBottomRightChar = $bottomRight;
$this->crossingBottomMidChar = $bottomMid;
$this->crossingBottomLeftChar = $bottomLeft;
$this->crossingMidLeftChar = $midLeft;
$this->crossingTopLeftBottomChar = $topLeftBottom ?? $midLeft;
$this->crossingTopMidBottomChar = $topMidBottom ?? $cross;
$this->crossingTopRightBottomChar = $topRightBottom ?? $midRight;
return $this;
}
/**
* Sets default crossing character used for each cross.
*
* @see {@link setCrossingChars()} for setting each crossing individually.
*/
public function setDefaultCrossingChar(string $char): self
{
return $this->setCrossingChars($char, $char, $char, $char, $char, $char, $char, $char, $char);
2018-02-01 20:01:12 +00:00
}
/**
* Gets crossing character.
*
2019-01-18 18:33:28 +00:00
* @return string
2018-02-01 20:01:12 +00:00
*/
public function getCrossingChar()
{
return $this->crossingChar;
}
/**
* Gets crossing characters.
*
* @internal
*/
public function getCrossingChars(): array
{
2019-06-11 11:29:32 +00:00
return [
$this->crossingChar,
$this->crossingTopLeftChar,
$this->crossingTopMidChar,
$this->crossingTopRightChar,
$this->crossingMidRightChar,
$this->crossingBottomRightChar,
$this->crossingBottomMidChar,
$this->crossingBottomLeftChar,
$this->crossingMidLeftChar,
$this->crossingTopLeftBottomChar,
$this->crossingTopMidBottomChar,
$this->crossingTopRightBottomChar,
2019-06-11 11:29:32 +00:00
];
}
2018-02-01 20:01:12 +00:00
/**
* Sets header cell format.
*
* @return $this
*/
2022-03-10 11:54:29 +00:00
public function setCellHeaderFormat(string $cellHeaderFormat)
2018-02-01 20:01:12 +00:00
{
$this->cellHeaderFormat = $cellHeaderFormat;
return $this;
}
/**
* Gets header cell format.
*
* @return string
*/
public function getCellHeaderFormat()
{
return $this->cellHeaderFormat;
}
/**
* Sets row cell format.
*
* @return $this
*/
2022-03-10 11:54:29 +00:00
public function setCellRowFormat(string $cellRowFormat)
2018-02-01 20:01:12 +00:00
{
$this->cellRowFormat = $cellRowFormat;
return $this;
}
/**
* Gets row cell format.
*
* @return string
*/
public function getCellRowFormat()
{
return $this->cellRowFormat;
}
/**
* Sets row cell content format.
*
* @return $this
*/
2022-03-10 11:54:29 +00:00
public function setCellRowContentFormat(string $cellRowContentFormat)
2018-02-01 20:01:12 +00:00
{
$this->cellRowContentFormat = $cellRowContentFormat;
return $this;
}
/**
* Gets row cell content format.
*
* @return string
*/
public function getCellRowContentFormat()
{
return $this->cellRowContentFormat;
}
/**
* Sets table border format.
*
* @return $this
*/
2022-03-10 11:54:29 +00:00
public function setBorderFormat(string $borderFormat)
2018-02-01 20:01:12 +00:00
{
$this->borderFormat = $borderFormat;
return $this;
}
/**
* Gets table border format.
*
* @return string
*/
public function getBorderFormat()
{
return $this->borderFormat;
}
/**
* Sets cell padding type.
*
* @return $this
*/
2022-03-10 11:54:29 +00:00
public function setPadType(int $padType)
2018-02-01 20:01:12 +00:00
{
2022-03-10 11:54:29 +00:00
if (!\in_array($padType, [\STR_PAD_LEFT, \STR_PAD_RIGHT, \STR_PAD_BOTH], true)) {
2018-02-01 20:01:12 +00:00
throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).');
}
$this->padType = $padType;
return $this;
}
/**
* Gets cell padding type.
*
* @return int
*/
public function getPadType()
{
return $this->padType;
}
2019-01-18 18:33:28 +00:00
public function getHeaderTitleFormat(): string
{
return $this->headerTitleFormat;
}
2022-03-10 11:54:29 +00:00
/**
* @return $this
*/
2019-01-18 18:33:28 +00:00
public function setHeaderTitleFormat(string $format): self
{
$this->headerTitleFormat = $format;
return $this;
}
public function getFooterTitleFormat(): string
{
return $this->footerTitleFormat;
}
2022-03-10 11:54:29 +00:00
/**
* @return $this
*/
2019-01-18 18:33:28 +00:00
public function setFooterTitleFormat(string $format): self
{
$this->footerTitleFormat = $format;
return $this;
}
2018-02-01 20:01:12 +00:00
}