"Fossies" - the Fresh Open Source Software Archive

Member "papayacms-core-6.9.4/src/system/Papaya/UI/Option/Align.php" (13 Dec 2019, 2315 Bytes) of package /linux/www/papayacms-core-6.9.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Align.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 /**
    3  * papaya CMS
    4  *
    5  * @copyright 2000-2018 by papayaCMS project - All rights reserved.
    6  * @link http://www.papaya-cms.com/
    7  * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, version 2
    8  *
    9  *  You can redistribute and/or modify this script under the terms of the GNU General Public
   10  *  License (GPL) version 2, provided that the copyright and license notes, including these
   11  *  lines, remain unmodified. papaya is distributed in the hope that it will be useful, but
   12  *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   13  *  FOR A PARTICULAR PURPOSE.
   14  */
   15 namespace Papaya\UI\Option;
   16 
   17 /**
   18  * Generic definition and handling for alignment attribute values.
   19  *
   20  * @package Papaya-Library
   21  * @subpackage UI
   22  */
   23 class Align {
   24   /**
   25    * Alignment left
   26    *
   27    * @var int
   28    */
   29   const LEFT = 0;
   30 
   31   /**
   32    * Alignment center
   33    *
   34    * @var int
   35    */
   36   const CENTER = 1;
   37 
   38   /**
   39    * Alignment right
   40    *
   41    * @var int
   42    */
   43   const RIGHT = 2;
   44 
   45   /**
   46    * string representation of the column alignment, used in the xml attributes
   47    *
   48    * @var array
   49    */
   50   private static $_alignAttributes = [
   51     self::LEFT => 'left',
   52     self::CENTER => 'center',
   53     self::RIGHT => 'right'
   54   ];
   55 
   56   /**
   57    * Get the string representation of the alignment value for a xml attribute. If the align
   58    * argument is invalid it will return "left".
   59    *
   60    * @param int $align
   61    *
   62    * @return string
   63    */
   64   public static function getString($align) {
   65     if (isset(self::$_alignAttributes[$align])) {
   66       return self::$_alignAttributes[$align];
   67     }
   68     return self::$_alignAttributes[self::LEFT];
   69   }
   70 
   71   /**
   72    * Validate an alignment value. This will throw an exception if the argument is invalid.
   73    * An individual message for the exception can be provided, too.
   74    *
   75    * @throws \InvalidArgumentException
   76    *
   77    * @param int $align
   78    * @param string $message
   79    *
   80    * @return true
   81    */
   82   public static function validate($align, $message = NULL) {
   83     if (isset(self::$_alignAttributes[$align])) {
   84       return TRUE;
   85     }
   86     if (NULL !== $message) {
   87       throw new \InvalidArgumentException($message);
   88     }
   89     throw new \InvalidArgumentException(
   90       \sprintf('InvalidArgumentException: Invalid align value "%d".', $align)
   91     );
   92   }
   93 }