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. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
type_cast_helper.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\request;
015
016 /**
017 * A helper class that provides convenience methods for type casting.
018 */
019 class type_cast_helper implements \phpbb\request\type_cast_helper_interface
020 {
021 /**
022 * Set variable $result to a particular type.
023 *
024 * @param mixed &$result The variable to fill
025 * @param mixed $var The contents to fill with
026 * @param mixed $type The variable type. Will be used with {@link settype()}
027 * @param bool $multibyte Indicates whether string values may contain UTF-8 characters.
028 * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks.
029 * @param bool $trim Indicates whether trim() should be applied to string values.
030 * Default is true.
031 */
032 public function set_var(&$result, $var, $type, $multibyte = false, $trim = true)
033 {
034 settype($var, $type);
035 $result = $var;
036
037 if ($type == 'string')
038 {
039 $result = strtr($result, ["\r\n" => "\n", "\r" => "\n", "\0" => '', "\u{FEFF}" => '']);
040
041 if ($trim)
042 {
043 $result = trim($result);
044 }
045
046 $result = htmlspecialchars($result, ENT_COMPAT, 'UTF-8');
047
048 if ($multibyte)
049 {
050 $result = utf8_normalize_nfc($result);
051 }
052
053 if (!empty($result))
054 {
055 // Make sure multibyte characters are wellformed
056 if ($multibyte)
057 {
058 if (!preg_match('//u', $result))
059 {
060 $result = '';
061 }
062 }
063 else
064 {
065 // no multibyte, allow only ASCII (0-127)
066 $result = preg_replace('/[\x80-\xFF]/', '?', $result);
067 }
068 }
069 }
070 }
071
072 /**
073 * Recursively sets a variable to a given type using {@link set_var set_var}
074 *
075 * @param string $var The value which shall be sanitised (passed by reference).
076 * @param mixed $default Specifies the type $var shall have.
077 * If it is an array and $var is not one, then an empty array is returned.
078 * Otherwise var is cast to the same type, and if $default is an array all
079 * keys and values are cast recursively using this function too.
080 * @param bool $multibyte Indicates whether string keys and values may contain UTF-8 characters.
081 * Default is false, causing all bytes outside the ASCII range (0-127) to
082 * be replaced with question marks.
083 * @param bool $trim Indicates whether trim() should be applied to string values.
084 * Default is true.
085 */
086 public function recursive_set_var(&$var, $default, $multibyte, $trim = true)
087 {
088 if (is_array($var) !== is_array($default))
089 {
090 $var = (is_array($default)) ? array() : $default;
091 return;
092 }
093
094 if (!is_array($default))
095 {
096 $type = gettype($default);
097 $this->set_var($var, $var, $type, $multibyte, $trim);
098 }
099 else
100 {
101 // make sure there is at least one key/value pair to use get the
102 // types from
103 if (empty($default))
104 {
105 $var = array();
106 return;
107 }
108
109 $default_key = key($default);
110 $default_value = current($default);
111 $key_type = gettype($default_key);
112
113 $_var = $var;
114 $var = array();
115
116 foreach ($_var as $k => $v)
117 {
118 $this->set_var($k, $k, $key_type, $multibyte);
119
120 $this->recursive_set_var($v, $default_value, $multibyte, $trim);
121 $var[$k] = $v;
122 }
123 }
124 }
125 }
126