[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Parser/AttributeFilters/ -> NumericFilter.php (source)

   1  <?php
   2  
   3  /*
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2019 The s9e Authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Parser\AttributeFilters;
   9  use s9e\TextFormatter\Parser\Logger;
  10  class NumericFilter
  11  {
  12  	public static function filterFloat($attrValue)
  13      {
  14          return \filter_var($attrValue, \FILTER_VALIDATE_FLOAT);
  15      }
  16  	public static function filterInt($attrValue)
  17      {
  18          return \filter_var($attrValue, \FILTER_VALIDATE_INT);
  19      }
  20  	public static function filterRange($attrValue, $min, $max, Logger $logger = \null)
  21      {
  22          $attrValue = \filter_var($attrValue, \FILTER_VALIDATE_INT);
  23          if ($attrValue === \false)
  24              return \false;
  25          if ($attrValue < $min)
  26          {
  27              if (isset($logger))
  28                  $logger->warn(
  29                      'Value outside of range, adjusted up to min value',
  30                      [
  31                          'attrValue' => $attrValue,
  32                          'min'       => $min,
  33                          'max'       => $max
  34                      ]
  35                  );
  36              return $min;
  37          }
  38          if ($attrValue > $max)
  39          {
  40              if (isset($logger))
  41                  $logger->warn(
  42                      'Value outside of range, adjusted down to max value',
  43                      [
  44                          'attrValue' => $attrValue,
  45                          'min'       => $min,
  46                          'max'       => $max
  47                      ]
  48                  );
  49              return $max;
  50          }
  51          return $attrValue;
  52      }
  53  	public static function filterUint($attrValue)
  54      {
  55          return \filter_var($attrValue, \FILTER_VALIDATE_INT, [
  56              'options' => ['min_range' => 0]
  57          ]);
  58      }
  59  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1