Cml\Console\Component\Box::render PHP Method

render() public method

渲染文本并返回
public render ( ) : string
return string
    public function render()
    {
        $lines = explode("\n", $this->text);
        $maxWidth = 0;
        foreach ($lines as $line) {
            if (strlen($line) > $maxWidth) {
                $maxWidth = strlen($line);
            }
        }
        $maxWidth += $this->padding * 2 + 2;
        $output = str_repeat($this->periphery, $maxWidth) . "\n";
        //first line
        foreach ($lines as $line) {
            $space = $maxWidth - (strlen($line) + 2 + $this->padding * 2);
            $output .= $this->periphery . str_repeat(' ', $this->padding) . $line . str_repeat(' ', $space + $this->padding) . $this->periphery . "\n";
        }
        $output .= str_repeat($this->periphery, $maxWidth);
        return $output;
    }