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 | /** |
| 30 | * PHP ext/standard/array compatibility package |
| 31 | * |
| 32 | * @package CodeIgniter |
| 33 | * @subpackage CodeIgniter |
| 34 | * @category Compatibility |
| 35 | * @author Andrey Andreev |
| 36 | * @link http://codeigniter.com/user_guide/ |
| 37 | * @link http://php.net/book.array |
| 38 | */ |
| 39 | |
| 40 | // ------------------------------------------------------------------------ |
| 41 | |
| 42 | if (is_php('5.5')) |
| 43 | { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | // ------------------------------------------------------------------------ |
| 48 | |
| 49 | if ( ! function_exists('array_column')) |
| 50 | { |
| 51 | /** |
| 52 | * array_column() |
| 53 | * |
| 54 | * @link http://php.net/array_column |
| 55 | * @param string $array |
| 56 | * @param mixed $column_key |
| 57 | * @param mixed $index_key |
| 58 | * @return array |
| 59 | */ |
| 60 | function array_column(array $array, $column_key, $index_key = NULL) |
| 61 | { |
| 62 | if ( ! in_array($type = gettype($column_key), array('integer', 'string', 'NULL'), TRUE)) |
| 63 | { |
| 64 | if ($type === 'double') |
| 65 | { |
| 66 | $column_key = (int) $column_key; |
| 67 | } |
| 68 | elseif ($type === 'object' && method_exists($column_key, '__toString')) |
| 69 | { |
| 70 | $column_key = (string) $column_key; |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING); |
| 75 | return FALSE; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if ( ! in_array($type = gettype($index_key), array('integer', 'string', 'NULL'), TRUE)) |
| 80 | { |
| 81 | if ($type === 'double') |
| 82 | { |
| 83 | $index_key = (int) $index_key; |
| 84 | } |
| 85 | elseif ($type === 'object' && method_exists($index_key, '__toString')) |
| 86 | { |
| 87 | $index_key = (string) $index_key; |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING); |
| 92 | return FALSE; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | $result = array(); |
| 97 | foreach ($array as &$a) |
| 98 | { |
| 99 | if ($column_key === NULL) |
| 100 | { |
| 101 | $value = $a; |
| 102 | } |
| 103 | elseif (is_array($a) && array_key_exists($column_key, $a)) |
| 104 | { |
| 105 | $value = $a[$column_key]; |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | continue; |
| 110 | } |
| 111 | |
| 112 | if ($index_key === NULL OR ! array_key_exists($index_key, $a)) |
| 113 | { |
| 114 | $result[] = $value; |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | $result[$a[$index_key]] = $value; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | return $result; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // ------------------------------------------------------------------------ |
| 127 | |
| 128 | if (is_php('5.3')) |
| 129 | { |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | // ------------------------------------------------------------------------ |
| 134 | |
| 135 | if ( ! function_exists('array_replace')) |
| 136 | { |
| 137 | /** |
| 138 | * array_replace() |
| 139 | * |
| 140 | * @link http://php.net/array_replace |
| 141 | * @return array |
| 142 | */ |
| 143 | function array_replace() |
| 144 | { |
| 145 | $arrays = func_get_args(); |
| 146 | |
| 147 | if (($c = count($arrays)) === 0) |
| 148 | { |
| 149 | trigger_error('array_replace() expects at least 1 parameter, 0 given', E_USER_WARNING); |
| 150 | return NULL; |
| 151 | } |
| 152 | elseif ($c === 1) |
| 153 | { |
| 154 | if ( ! is_array($arrays[0])) |
| 155 | { |
| 156 | trigger_error('array_replace(): Argument #1 is not an array', E_USER_WARNING); |
| 157 | return NULL; |
| 158 | } |
| 159 | |
| 160 | return $arrays[0]; |
| 161 | } |
| 162 | |
| 163 | $array = array_shift($arrays); |
| 164 | $c--; |
| 165 | |
| 166 | for ($i = 0, $c = count($arrays); $i < $c; $i++) |
| 167 | { |
| 168 | if ( ! is_array($arrays[$i])) |
| 169 | { |
| 170 | trigger_error('array_replace(): Argument #'.($i + 2).' is not an array', E_USER_WARNING); |
| 171 | return NULL; |
| 172 | } |
| 173 | elseif (empty($arrays[$i])) |
| 174 | { |
| 175 | continue; |
| 176 | } |
| 177 | |
| 178 | foreach (array_keys($arrays[$i]) as $key) |
| 179 | { |
| 180 | $array[$key] = $arrays[$i][$key]; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | return $array; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | // ------------------------------------------------------------------------ |
| 189 | |
| 190 | if ( ! function_exists('array_replace_recursive')) |
| 191 | { |
| 192 | /** |
| 193 | * array_replace_recursive() |
| 194 | * |
| 195 | * @link http://php.net/array_replace_recursive |
| 196 | * @return array |
| 197 | */ |
| 198 | function array_replace_recursive() |
| 199 | { |
| 200 | $arrays = func_get_args(); |
| 201 | |
| 202 | if (($c = count($arrays)) === 0) |
| 203 | { |
| 204 | trigger_error('array_replace_recursive() expects at least 1 parameter, 0 given', E_USER_WARNING); |
| 205 | return NULL; |
| 206 | } |
| 207 | elseif ($c === 1) |
| 208 | { |
| 209 | if ( ! is_array($arrays[0])) |
| 210 | { |
| 211 | trigger_error('array_replace_recursive(): Argument #1 is not an array', E_USER_WARNING); |
| 212 | return NULL; |
| 213 | } |
| 214 | |
| 215 | return $arrays[0]; |
| 216 | } |
| 217 | |
| 218 | $array = array_shift($arrays); |
| 219 | $c--; |
| 220 | |
| 221 | for ($i = 0, $c = count($arrays); $i < $c; $i++) |
| 222 | { |
| 223 | if ( ! is_array($arrays[$i])) |
| 224 | { |
| 225 | trigger_error('array_replace_recursive(): Argument #'.($i + 2).' is not an array', E_USER_WARNING); |
| 226 | return NULL; |
| 227 | } |
| 228 | elseif (empty($arrays[$i])) |
| 229 | { |
| 230 | continue; |
| 231 | } |
| 232 | |
| 233 | foreach (array_keys($arrays[$i]) as $key) |
| 234 | { |
| 235 | $array[$key] = (is_array($arrays[$i][$key]) && isset($array[$key]) && is_array($array[$key])) |
| 236 | ? array_replace_recursive($array[$key], $arrays[$i][$key]) |
| 237 | : $arrays[$i][$key]; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | return $array; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /* End of file array.php */ |
| 246 | /* Location: ./system/core/compat/array.php */ |