Ejemplo n.º 1
0
 /**
  * Add a border around the content.
  *
  * @param string $content The content, without border
  *
  * @return array The content, with border
  */
 private function addBorder(array $content = [])
 {
     // Get the full width, including padding
     $width = $this->width + 2 * $this->styles['paddingX'];
     // Get and color the character used for the left and right sides
     $color = $this->graphite->setColor($this->styles['borderColor']);
     $side = $color->encode($this->styles['borderStyle']['vertical']);
     // Append and prepend the left/right character to each line of content
     foreach ($content as $i => $line) {
         $content[$i] = $side . $line . $side;
     }
     // Create the top border
     $char = $this->styles['borderStyle']['horizontal'];
     if ($this->title !== null) {
         $title = str_pad($this->title, strlen($this->title) + 2, ' ', STR_PAD_BOTH);
         $top = $title . $this->graphite->repeat($char, $width - strlen($title));
     } else {
         $top = $this->graphite->repeat($char, $width);
     }
     $topLeft = $this->styles['borderStyle']['topLeft'];
     $topRight = $this->styles['borderStyle']['topRight'];
     $top = $topLeft . $top . $topRight;
     // Color the top border
     $color = $this->graphite->setColor($this->styles['borderColor']);
     $top = $color->encode($top);
     // Add the top border to the content
     array_unshift($content, $top);
     // Create the bottom border
     $bottom = $this->graphite->repeat($this->styles['borderStyle']['horizontal'], $width);
     $bottomLeft = $this->styles['borderStyle']['bottomLeft'];
     $bottomRight = $this->styles['borderStyle']['bottomRight'];
     $bottom = $bottomLeft . $bottom . $bottomRight;
     // Color the bottom border
     $color = $this->graphite->setColor($this->styles['borderColor']);
     $bottom = $color->encode($bottom);
     // Add the bottom border to the content
     array_push($content, $bottom);
     return $content;
 }