class OutputFormatterStyleStack in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/console/Formatter/OutputFormatterStyleStack.php \Symfony\Component\Console\Formatter\OutputFormatterStyleStack
@author Jean-François Simon <contact@jfsimon.fr>
Hierarchy
- class \Symfony\Component\Console\Formatter\OutputFormatterStyleStack
Expanded class hierarchy of OutputFormatterStyleStack
1 file declares its use of OutputFormatterStyleStack
- OutputFormatterStyleStackTest.php in vendor/
symfony/ console/ Tests/ Formatter/ OutputFormatterStyleStackTest.php
File
- vendor/
symfony/ console/ Formatter/ OutputFormatterStyleStack.php, line 17
Namespace
Symfony\Component\Console\FormatterView source
class OutputFormatterStyleStack {
/**
* @var OutputFormatterStyleInterface[]
*/
private $styles;
/**
* @var OutputFormatterStyleInterface
*/
private $emptyStyle;
/**
* Constructor.
*
* @param OutputFormatterStyleInterface|null $emptyStyle
*/
public function __construct(OutputFormatterStyleInterface $emptyStyle = null) {
$this->emptyStyle = $emptyStyle ?: new OutputFormatterStyle();
$this
->reset();
}
/**
* Resets stack (ie. empty internal arrays).
*/
public function reset() {
$this->styles = array();
}
/**
* Pushes a style in the stack.
*
* @param OutputFormatterStyleInterface $style
*/
public function push(OutputFormatterStyleInterface $style) {
$this->styles[] = $style;
}
/**
* Pops a style from the stack.
*
* @param OutputFormatterStyleInterface|null $style
*
* @return OutputFormatterStyleInterface
*
* @throws \InvalidArgumentException When style tags incorrectly nested
*/
public function pop(OutputFormatterStyleInterface $style = null) {
if (empty($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.
*
* @return OutputFormatterStyle
*/
public function getCurrent() {
if (empty($this->styles)) {
return $this->emptyStyle;
}
return $this->styles[count($this->styles) - 1];
}
/**
* @param OutputFormatterStyleInterface $emptyStyle
*
* @return OutputFormatterStyleStack
*/
public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) {
$this->emptyStyle = $emptyStyle;
return $this;
}
/**
* @return OutputFormatterStyleInterface
*/
public function getEmptyStyle() {
return $this->emptyStyle;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OutputFormatterStyleStack:: |
private | property | ||
OutputFormatterStyleStack:: |
private | property | ||
OutputFormatterStyleStack:: |
public | function | Computes current style with stacks top codes. | |
OutputFormatterStyleStack:: |
public | function | ||
OutputFormatterStyleStack:: |
public | function | Pops a style from the stack. | |
OutputFormatterStyleStack:: |
public | function | Pushes a style in the stack. | |
OutputFormatterStyleStack:: |
public | function | Resets stack (ie. empty internal arrays). | |
OutputFormatterStyleStack:: |
public | function | ||
OutputFormatterStyleStack:: |
public | function | Constructor. |