Webmozart\Console\UI\Layout\BlockLayout::add PHP 메소드

add() 공개 메소드

Adds a renderable element to the layout.
public add ( Webmozart\Console\UI\Component $element ) : static
$element Webmozart\Console\UI\Component The element to add.
리턴 static The current instance.
    public function add(Component $element)
    {
        $this->elements[] = $element;
        $this->indentations[] = $this->currentIndentation;
        if ($element instanceof LabeledParagraph) {
            $this->alignment->add($element, $this->currentIndentation);
            $element->setAlignment($this->alignment);
        }
        return $this;
    }

Usage Example

예제 #1
0
    public function testRenderWithIndentation()
    {
        $layout = new BlockLayout();
        $layout->add(new Paragraph('HEADING 1'))->add(new Paragraph(self::LOREM_IPSUM))->add(new EmptyLine())->add(new LabeledParagraph('Not Aligned', self::LOREM_IPSUM, 1, false))->add(new EmptyLine())->add(new Paragraph('HEADING 2'))->beginBlock()->add(new LabeledParagraph('Label 1', self::LOREM_IPSUM))->add(new LabeledParagraph('Label 2', self::LOREM_IPSUM))->endBlock()->add(new Paragraph('HEADING 3'))->beginBlock()->add(new LabeledParagraph('Longer Label', self::LOREM_IPSUM))->endBlock();
        $layout->render($this->io, 4);
        $expected = <<<'EOF'
    HEADING 1
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
    eirmod tempor invidunt

    Not Aligned Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
                diam nonumy eirmod tempor invidunt

    HEADING 2
      Label 1       Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
                    sed diam nonumy eirmod tempor invidunt
      Label 2       Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
                    sed diam nonumy eirmod tempor invidunt
    HEADING 3
      Longer Label  Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
                    sed diam nonumy eirmod tempor invidunt

EOF;
        $this->assertSame($expected, $this->io->fetchOutput());
    }
All Usage Examples Of Webmozart\Console\UI\Layout\BlockLayout::add