[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/symfony/console/Helper/ -> TableCellStyle.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <[email protected]>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\Console\Helper;
  13  
  14  use Symfony\Component\Console\Exception\InvalidArgumentException;
  15  
  16  /**
  17   * @author Yewhen Khoptynskyi <[email protected]>
  18   */
  19  class TableCellStyle
  20  {
  21      public const DEFAULT_ALIGN = 'left';
  22  
  23      private const TAG_OPTIONS = [
  24          'fg',
  25          'bg',
  26          'options',
  27      ];
  28  
  29      private const ALIGN_MAP = [
  30          'left' => \STR_PAD_RIGHT,
  31          'center' => \STR_PAD_BOTH,
  32          'right' => \STR_PAD_LEFT,
  33      ];
  34  
  35      private $options = [
  36          'fg' => 'default',
  37          'bg' => 'default',
  38          'options' => null,
  39          'align' => self::DEFAULT_ALIGN,
  40          'cellFormat' => null,
  41      ];
  42  
  43      public function __construct(array $options = [])
  44      {
  45          if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
  46              throw new InvalidArgumentException(sprintf('The TableCellStyle does not support the following options: \'%s\'.', implode('\', \'', $diff)));
  47          }
  48  
  49          if (isset($options['align']) && !\array_key_exists($options['align'], self::ALIGN_MAP)) {
  50              throw new InvalidArgumentException(sprintf('Wrong align value. Value must be following: \'%s\'.', implode('\', \'', array_keys(self::ALIGN_MAP))));
  51          }
  52  
  53          $this->options = array_merge($this->options, $options);
  54      }
  55  
  56      public function getOptions(): array
  57      {
  58          return $this->options;
  59      }
  60  
  61      /**
  62       * Gets options we need for tag for example fg, bg.
  63       *
  64       * @return string[]
  65       */
  66      public function getTagOptions()
  67      {
  68          return array_filter(
  69              $this->getOptions(),
  70              function ($key) {
  71                  return \in_array($key, self::TAG_OPTIONS) && isset($this->options[$key]);
  72              },
  73              \ARRAY_FILTER_USE_KEY
  74          );
  75      }
  76  
  77      /**
  78       * @return int
  79       */
  80      public function getPadByAlign()
  81      {
  82          return self::ALIGN_MAP[$this->getOptions()['align']];
  83      }
  84  
  85      public function getCellFormat(): ?string
  86      {
  87          return $this->getOptions()['cellFormat'];
  88      }
  89  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer