Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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

StringUtils.php

Zuletzt modifiziert: 09.10.2024, 12:55 - Dateigröße: 5.32 KiB


 001  <?php
 002  /**
 003   * Zend Framework (http://framework.zend.com/)
 004   *
 005   * @link      http://github.com/zendframework/zf2 for the canonical source repository
 006   * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 007   * @license   http://framework.zend.com/license/new-bsd New BSD License
 008   */
 009   
 010  namespace Zend\Stdlib;
 011   
 012  use Zend\Stdlib\StringWrapper\StringWrapperInterface;
 013   
 014  /**
 015   * Utility class for handling strings of different character encodings
 016   * using available PHP extensions.
 017   *
 018   * Declared abstract, as we have no need for instantiation.
 019   */
 020  abstract class StringUtils
 021  {
 022      /**
 023       * Ordered list of registered string wrapper instances
 024       *
 025       * @var StringWrapperInterface[]
 026       */
 027      protected static $wrapperRegistry = null;
 028   
 029      /**
 030       * A list of known single-byte character encodings (upper-case)
 031       *
 032       * @var string[]
 033       */
 034      protected static $singleByteEncodings = array(
 035          'ASCII', '7BIT', '8BIT',
 036          'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5',
 037          'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10',
 038          'ISO-8859-11', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16',
 039          'CP-1251', 'CP-1252',
 040          // TODO
 041      );
 042   
 043      /**
 044       * Is PCRE compiled with Unicode support?
 045       *
 046       * @var bool
 047       **/
 048      protected static $hasPcreUnicodeSupport = null;
 049   
 050      /**
 051       * Get registered wrapper classes
 052       *
 053       * @return string[]
 054       */
 055      public static function getRegisteredWrappers()
 056      {
 057          if (static::$wrapperRegistry === null) {
 058              static::$wrapperRegistry = array();
 059   
 060              if (extension_loaded('intl')) {
 061                  static::$wrapperRegistry[] = 'Zend\Stdlib\StringWrapper\Intl';
 062              }
 063   
 064              if (extension_loaded('mbstring')) {
 065                  static::$wrapperRegistry[] = 'Zend\Stdlib\StringWrapper\MbString';
 066              }
 067   
 068              if (extension_loaded('iconv')) {
 069                  static::$wrapperRegistry[] = 'Zend\Stdlib\StringWrapper\Iconv';
 070              }
 071   
 072              static::$wrapperRegistry[] = 'Zend\Stdlib\StringWrapper\Native';
 073          }
 074   
 075          return static::$wrapperRegistry;
 076      }
 077   
 078      /**
 079       * Register a string wrapper class
 080       *
 081       * @param string $wrapper
 082       * @return void
 083       */
 084      public static function registerWrapper($wrapper)
 085      {
 086          $wrapper = (string) $wrapper;
 087          if (!in_array($wrapper, static::$wrapperRegistry, true)) {
 088              static::$wrapperRegistry[] = $wrapper;
 089          }
 090      }
 091   
 092      /**
 093       * Unregister a string wrapper class
 094       *
 095       * @param string $wrapper
 096       * @return void
 097       */
 098      public static function unregisterWrapper($wrapper)
 099      {
 100          $index = array_search((string) $wrapper, static::$wrapperRegistry, true);
 101          if ($index !== false) {
 102              unset(static::$wrapperRegistry[$index]);
 103          }
 104      }
 105   
 106      /**
 107       * Reset all registered wrappers so the default wrappers will be used
 108       *
 109       * @return void
 110       */
 111      public static function resetRegisteredWrappers()
 112      {
 113          static::$wrapperRegistry = null;
 114      }
 115   
 116      /**
 117       * Get the first string wrapper supporting the given character encoding
 118       * and supports to convert into the given convert encoding.
 119       *
 120       * @param string      $encoding        Character encoding to support
 121       * @param string|null $convertEncoding OPTIONAL character encoding to convert in
 122       * @return StringWrapperInterface
 123       * @throws Exception\RuntimeException If no wrapper supports given character encodings
 124       */
 125      public static function getWrapper($encoding = 'UTF-8', $convertEncoding = null)
 126      {
 127          foreach (static::getRegisteredWrappers() as $wrapperClass) {
 128              if ($wrapperClass::isSupported($encoding, $convertEncoding)) {
 129                  $wrapper = new $wrapperClass($encoding, $convertEncoding);
 130                  $wrapper->setEncoding($encoding, $convertEncoding);
 131                  return $wrapper;
 132              }
 133          }
 134   
 135          throw new Exception\RuntimeException(
 136              'No wrapper found supporting "' . $encoding . '"'
 137              . (($convertEncoding !== null) ? ' and "' . $convertEncoding . '"' : '')
 138          );
 139      }
 140   
 141      /**
 142       * Get a list of all known single-byte character encodings
 143       *
 144       * @return string[]
 145       */
 146      public static function getSingleByteEncodings()
 147      {
 148          return static::$singleByteEncodings;
 149      }
 150   
 151      /**
 152       * Check if a given encoding is a known single-byte character encoding
 153       *
 154       * @param string $encoding
 155       * @return bool
 156       */
 157      public static function isSingleByteEncoding($encoding)
 158      {
 159          return in_array(strtoupper($encoding), static::$singleByteEncodings);
 160      }
 161   
 162      /**
 163       * Check if a given string is valid UTF-8 encoded
 164       *
 165       * @param string $str
 166       * @return bool
 167       */
 168      public static function isValidUtf8($str)
 169      {
 170          return is_string($str) && ($str === '' || preg_match('/^./su', $str) == 1);
 171      }
 172   
 173      /**
 174       * Is PCRE compiled with Unicode support?
 175       *
 176       * @return bool
 177       */
 178      public static function hasPcreUnicodeSupport()
 179      {
 180          if (static::$hasPcreUnicodeSupport === null) {
 181              ErrorHandler::start();
 182              static::$hasPcreUnicodeSupport = defined('PREG_BAD_UTF8_OFFSET_ERROR') && preg_match('/\pL/u', 'a') == 1;
 183              ErrorHandler::stop();
 184          }
 185          return static::$hasPcreUnicodeSupport;
 186      }
 187  }
 188