Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 1 | <?php |
| 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 5.2.4 or newer |
| 6 | * |
| 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
| 19 | * @package CodeIgniter |
| 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
| 23 | * @link http://codeigniter.com |
| 24 | * @since Version 3.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
| 28 | |
| 29 | /** |
Andrey Andreev | 5b3fe7c | 2014-07-07 10:55:53 +0300 | [diff] [blame^] | 30 | * PHP ext/standard compatibility package |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 31 | * |
| 32 | * @package CodeIgniter |
| 33 | * @subpackage CodeIgniter |
| 34 | * @category Compatibility |
| 35 | * @author Andrey Andreev |
| 36 | * @link http://codeigniter.com/user_guide/ |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | // ------------------------------------------------------------------------ |
| 40 | |
| 41 | if (is_php('5.5')) |
| 42 | { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | // ------------------------------------------------------------------------ |
| 47 | |
| 48 | if ( ! function_exists('array_column')) |
| 49 | { |
| 50 | /** |
| 51 | * array_column() |
| 52 | * |
| 53 | * @link http://php.net/array_column |
| 54 | * @param string $array |
| 55 | * @param mixed $column_key |
| 56 | * @param mixed $index_key |
| 57 | * @return array |
| 58 | */ |
| 59 | function array_column(array $array, $column_key, $index_key = NULL) |
| 60 | { |
| 61 | if ( ! in_array($type = gettype($column_key), array('integer', 'string', 'NULL'), TRUE)) |
| 62 | { |
| 63 | if ($type === 'double') |
| 64 | { |
| 65 | $column_key = (int) $column_key; |
| 66 | } |
| 67 | elseif ($type === 'object' && method_exists($column_key, '__toString')) |
| 68 | { |
| 69 | $column_key = (string) $column_key; |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING); |
| 74 | return FALSE; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | if ( ! in_array($type = gettype($index_key), array('integer', 'string', 'NULL'), TRUE)) |
| 79 | { |
| 80 | if ($type === 'double') |
| 81 | { |
| 82 | $index_key = (int) $index_key; |
| 83 | } |
| 84 | elseif ($type === 'object' && method_exists($index_key, '__toString')) |
| 85 | { |
| 86 | $index_key = (string) $index_key; |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING); |
| 91 | return FALSE; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | $result = array(); |
| 96 | foreach ($array as &$a) |
| 97 | { |
| 98 | if ($column_key === NULL) |
| 99 | { |
| 100 | $value = $a; |
| 101 | } |
| 102 | elseif (is_array($a) && array_key_exists($column_key, $a)) |
| 103 | { |
| 104 | $value = $a[$column_key]; |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | continue; |
| 109 | } |
| 110 | |
| 111 | if ($index_key === NULL OR ! array_key_exists($index_key, $a)) |
| 112 | { |
| 113 | $result[] = $value; |
| 114 | } |
| 115 | else |
| 116 | { |
| 117 | $result[$a[$index_key]] = $value; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return $result; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // ------------------------------------------------------------------------ |
| 126 | |
Andrey Andreev | 5b3fe7c | 2014-07-07 10:55:53 +0300 | [diff] [blame^] | 127 | if (is_php('5.4')) |
| 128 | { |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | // ------------------------------------------------------------------------ |
| 133 | |
| 134 | if ( ! function_exists('hex2bin')) |
| 135 | { |
| 136 | /** |
| 137 | * hex2bin() |
| 138 | * |
| 139 | * @link http://php.net/hex2bin |
| 140 | * @param string $data |
| 141 | * @return string |
| 142 | */ |
| 143 | function hex2bin($data) |
| 144 | { |
| 145 | if (in_array($type = gettype($data), array('array', 'double', 'object'), TRUE)) |
| 146 | { |
| 147 | if ($type === 'object' && method_exists($data, '__toString')) |
| 148 | { |
| 149 | $data = (string) $data; |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | trigger_error('hex2bin() expects parameter 1 to be string, '.$type.' given', E_USER_WARNING); |
| 154 | return NULL; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | if (strlen($data) % 2 !== 0) |
| 159 | { |
| 160 | trigger_error('Hexadecimal input string must have an even length', E_USER_WARNING); |
| 161 | return FALSE; |
| 162 | } |
| 163 | elseif ( ! preg_match('/^[0-9a-f]*$/i', $data)) |
| 164 | { |
| 165 | trigger_error('Input string must be hexadecimal string', E_USER_WARNING); |
| 166 | return FALSE; |
| 167 | } |
| 168 | |
| 169 | return pack('H*', $data); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // ------------------------------------------------------------------------ |
| 174 | |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 175 | if (is_php('5.3')) |
| 176 | { |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | // ------------------------------------------------------------------------ |
| 181 | |
| 182 | if ( ! function_exists('array_replace')) |
| 183 | { |
| 184 | /** |
| 185 | * array_replace() |
| 186 | * |
| 187 | * @link http://php.net/array_replace |
| 188 | * @return array |
| 189 | */ |
| 190 | function array_replace() |
| 191 | { |
| 192 | $arrays = func_get_args(); |
| 193 | |
| 194 | if (($c = count($arrays)) === 0) |
| 195 | { |
| 196 | trigger_error('array_replace() expects at least 1 parameter, 0 given', E_USER_WARNING); |
| 197 | return NULL; |
| 198 | } |
| 199 | elseif ($c === 1) |
| 200 | { |
| 201 | if ( ! is_array($arrays[0])) |
| 202 | { |
| 203 | trigger_error('array_replace(): Argument #1 is not an array', E_USER_WARNING); |
| 204 | return NULL; |
| 205 | } |
| 206 | |
| 207 | return $arrays[0]; |
| 208 | } |
| 209 | |
| 210 | $array = array_shift($arrays); |
| 211 | $c--; |
| 212 | |
Andrey Andreev | fd6efad | 2014-04-29 01:00:42 +0300 | [diff] [blame] | 213 | for ($i = 0; $i < $c; $i++) |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 214 | { |
| 215 | if ( ! is_array($arrays[$i])) |
| 216 | { |
| 217 | trigger_error('array_replace(): Argument #'.($i + 2).' is not an array', E_USER_WARNING); |
| 218 | return NULL; |
| 219 | } |
| 220 | elseif (empty($arrays[$i])) |
| 221 | { |
| 222 | continue; |
| 223 | } |
| 224 | |
| 225 | foreach (array_keys($arrays[$i]) as $key) |
| 226 | { |
| 227 | $array[$key] = $arrays[$i][$key]; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | return $array; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // ------------------------------------------------------------------------ |
| 236 | |
| 237 | if ( ! function_exists('array_replace_recursive')) |
| 238 | { |
| 239 | /** |
| 240 | * array_replace_recursive() |
| 241 | * |
| 242 | * @link http://php.net/array_replace_recursive |
| 243 | * @return array |
| 244 | */ |
| 245 | function array_replace_recursive() |
| 246 | { |
| 247 | $arrays = func_get_args(); |
| 248 | |
| 249 | if (($c = count($arrays)) === 0) |
| 250 | { |
| 251 | trigger_error('array_replace_recursive() expects at least 1 parameter, 0 given', E_USER_WARNING); |
| 252 | return NULL; |
| 253 | } |
| 254 | elseif ($c === 1) |
| 255 | { |
| 256 | if ( ! is_array($arrays[0])) |
| 257 | { |
| 258 | trigger_error('array_replace_recursive(): Argument #1 is not an array', E_USER_WARNING); |
| 259 | return NULL; |
| 260 | } |
| 261 | |
| 262 | return $arrays[0]; |
| 263 | } |
| 264 | |
| 265 | $array = array_shift($arrays); |
| 266 | $c--; |
| 267 | |
Andrey Andreev | fd6efad | 2014-04-29 01:00:42 +0300 | [diff] [blame] | 268 | for ($i = 0; $i < $c; $i++) |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 269 | { |
| 270 | if ( ! is_array($arrays[$i])) |
| 271 | { |
| 272 | trigger_error('array_replace_recursive(): Argument #'.($i + 2).' is not an array', E_USER_WARNING); |
| 273 | return NULL; |
| 274 | } |
| 275 | elseif (empty($arrays[$i])) |
| 276 | { |
| 277 | continue; |
| 278 | } |
| 279 | |
| 280 | foreach (array_keys($arrays[$i]) as $key) |
| 281 | { |
| 282 | $array[$key] = (is_array($arrays[$i][$key]) && isset($array[$key]) && is_array($array[$key])) |
| 283 | ? array_replace_recursive($array[$key], $arrays[$i][$key]) |
| 284 | : $arrays[$i][$key]; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | return $array; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /* End of file array.php */ |
| 293 | /* Location: ./system/core/compat/array.php */ |