Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

NumericFilter.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 2.09 KiB


001  <?php
002   
003  /**
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2022 The s9e authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Parser\AttributeFilters;
009   
010  use s9e\TextFormatter\Parser\Logger;
011   
012  class NumericFilter
013  {
014      /**
015      * Filter a float value
016      *
017      * @param  string $attrValue Original value
018      * @return mixed             Filtered value, or FALSE if invalid
019      */
020      public static function filterFloat($attrValue)
021      {
022          return filter_var($attrValue, FILTER_VALIDATE_FLOAT);
023      }
024   
025      /**
026      * Filter an int value
027      *
028      * @param  string $attrValue Original value
029      * @return mixed             Filtered value, or FALSE if invalid
030      */
031      public static function filterInt($attrValue)
032      {
033          return filter_var($attrValue, FILTER_VALIDATE_INT);
034      }
035   
036      /**
037      * Filter a range value
038      *
039      * @param  string  $attrValue Original value
040      * @param  integer $min       Minimum value
041      * @param  integer $max       Maximum value
042      * @param  Logger  $logger    Parser's Logger instance
043      * @return mixed              Filtered value, or FALSE if invalid
044      */
045      public static function filterRange($attrValue, $min, $max, Logger $logger = null)
046      {
047          $attrValue = filter_var($attrValue, FILTER_VALIDATE_INT);
048   
049          if ($attrValue === false)
050          {
051              return false;
052          }
053   
054          if ($attrValue < $min)
055          {
056              if (isset($logger))
057              {
058                  $logger->warn(
059                      'Value outside of range, adjusted up to min value',
060                      [
061                          'attrValue' => $attrValue,
062                          'min'       => $min,
063                          'max'       => $max
064                      ]
065                  );
066              }
067   
068              return $min;
069          }
070   
071          if ($attrValue > $max)
072          {
073              if (isset($logger))
074              {
075                  $logger->warn(
076                      'Value outside of range, adjusted down to max value',
077                      [
078                          'attrValue' => $attrValue,
079                          'min'       => $min,
080                          'max'       => $max
081                      ]
082                  );
083              }
084   
085              return $max;
086          }
087   
088          return $attrValue;
089      }
090   
091      /**
092      * Filter a uint value
093      *
094      * @param  string $attrValue Original value
095      * @return mixed             Filtered value, or FALSE if invalid
096      */
097      public static function filterUint($attrValue)
098      {
099          return filter_var($attrValue, FILTER_VALIDATE_INT, [
100              'options' => ['min_range' => 0]
101          ]);
102      }
103  }