Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace OpenSpout\Common\Entity\Style;
   6  
   7  use OpenSpout\Writer\Exception\Border\InvalidNameException;
   8  use OpenSpout\Writer\Exception\Border\InvalidStyleException;
   9  use OpenSpout\Writer\Exception\Border\InvalidWidthException;
  10  
  11  final class BorderPart
  12  {
  13      public const allowedStyles = [
  14          Border::STYLE_NONE,
  15          Border::STYLE_SOLID,
  16          Border::STYLE_DASHED,
  17          Border::STYLE_DOTTED,
  18          Border::STYLE_DOUBLE,
  19      ];
  20  
  21      public const allowedNames = [
  22          Border::LEFT,
  23          Border::RIGHT,
  24          Border::TOP,
  25          Border::BOTTOM,
  26      ];
  27  
  28      public const allowedWidths = [
  29          Border::WIDTH_THIN,
  30          Border::WIDTH_MEDIUM,
  31          Border::WIDTH_THICK,
  32      ];
  33  
  34      private string $style;
  35      private string $name;
  36      private string $color;
  37      private string $width;
  38  
  39      /**
  40       * @param string $name  @see  BorderPart::allowedNames
  41       * @param string $color A RGB color code
  42       * @param string $width @see BorderPart::allowedWidths
  43       * @param string $style @see BorderPart::allowedStyles
  44       *
  45       * @throws InvalidNameException
  46       * @throws InvalidStyleException
  47       * @throws InvalidWidthException
  48       */
  49      public function __construct(
  50          string $name,
  51          string $color = Color::BLACK,
  52          string $width = Border::WIDTH_MEDIUM,
  53          string $style = Border::STYLE_SOLID
  54      ) {
  55          if (!\in_array($name, self::allowedNames, true)) {
  56              throw new InvalidNameException($name);
  57          }
  58          if (!\in_array($style, self::allowedStyles, true)) {
  59              throw new InvalidStyleException($style);
  60          }
  61          if (!\in_array($width, self::allowedWidths, true)) {
  62              throw new InvalidWidthException($width);
  63          }
  64  
  65          $this->name = $name;
  66          $this->color = $color;
  67          $this->width = $width;
  68          $this->style = $style;
  69      }
  70  
  71      public function getName(): string
  72      {
  73          return $this->name;
  74      }
  75  
  76      public function getStyle(): string
  77      {
  78          return $this->style;
  79      }
  80  
  81      public function getColor(): string
  82      {
  83          return $this->color;
  84      }
  85  
  86      public function getWidth(): string
  87      {
  88          return $this->width;
  89      }
  90  }