class OutputFormatterStyleStack
@author Jean-François Simon <contact@jfsimon.fr>
Hierarchy
- class \Symfony\Component\Console\Formatter\OutputFormatterStyleStack implements \Symfony\Contracts\Service\ResetInterface
Expanded class hierarchy of OutputFormatterStyleStack
File
-
vendor/
symfony/ console/ Formatter/ OutputFormatterStyleStack.php, line 20
Namespace
Symfony\Component\Console\FormatterView source
class OutputFormatterStyleStack implements ResetInterface {
/**
* @var OutputFormatterStyleInterface[]
*/
private array $styles = [];
private OutputFormatterStyleInterface $emptyStyle;
public function __construct(?OutputFormatterStyleInterface $emptyStyle = null) {
$this->emptyStyle = $emptyStyle ?? new OutputFormatterStyle();
$this->reset();
}
/**
* Resets stack (ie. empty internal arrays).
*/
public function reset() : void {
$this->styles = [];
}
/**
* Pushes a style in the stack.
*/
public function push(OutputFormatterStyleInterface $style) : void {
$this->styles[] = $style;
}
/**
* Pops a style from the stack.
*
* @throws InvalidArgumentException When style tags incorrectly nested
*/
public function pop(?OutputFormatterStyleInterface $style = null) : OutputFormatterStyleInterface {
if (!$this->styles) {
return $this->emptyStyle;
}
if (null === $style) {
return array_pop($this->styles);
}
foreach (array_reverse($this->styles, true) as $index => $stackedStyle) {
if ($style->apply('') === $stackedStyle->apply('')) {
$this->styles = \array_slice($this->styles, 0, $index);
return $stackedStyle;
}
}
throw new InvalidArgumentException('Incorrectly nested style tag found.');
}
/**
* Computes current style with stacks top codes.
*/
public function getCurrent() : OutputFormatterStyleInterface {
if (!$this->styles) {
return $this->emptyStyle;
}
return $this->styles[\count($this->styles) - 1];
}
/**
* @return $this
*/
public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) : static {
$this->emptyStyle = $emptyStyle;
return $this;
}
public function getEmptyStyle() : OutputFormatterStyleInterface {
return $this->emptyStyle;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
OutputFormatterStyleStack::$emptyStyle | private | property | ||
OutputFormatterStyleStack::$styles | private | property | ||
OutputFormatterStyleStack::getCurrent | public | function | Computes current style with stacks top codes. | |
OutputFormatterStyleStack::getEmptyStyle | public | function | ||
OutputFormatterStyleStack::pop | public | function | Pops a style from the stack. | |
OutputFormatterStyleStack::push | public | function | Pushes a style in the stack. | |
OutputFormatterStyleStack::reset | public | function | Resets stack (ie. empty internal arrays). | Overrides ResetInterface::reset |
OutputFormatterStyleStack::setEmptyStyle | public | function | ||
OutputFormatterStyleStack::__construct | public | function |