Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 1 | <?php |
| 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 9 | * Copyright (c) 2014 - 2018, British Columbia Institute of Technology |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 32 | * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 3.0.0 |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
| 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
| 39 | |
| 40 | /** |
Andrey Andreev | 5b3fe7c | 2014-07-07 10:55:53 +0300 | [diff] [blame] | 41 | * PHP ext/standard compatibility package |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 42 | * |
| 43 | * @package CodeIgniter |
| 44 | * @subpackage CodeIgniter |
| 45 | * @category Compatibility |
| 46 | * @author Andrey Andreev |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 47 | * @link https://codeigniter.com/user_guide/ |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 48 | */ |
| 49 | |
| 50 | // ------------------------------------------------------------------------ |
| 51 | |
| 52 | if (is_php('5.5')) |
| 53 | { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | // ------------------------------------------------------------------------ |
| 58 | |
| 59 | if ( ! function_exists('array_column')) |
| 60 | { |
| 61 | /** |
| 62 | * array_column() |
| 63 | * |
| 64 | * @link http://php.net/array_column |
Andrey Andreev | e13fa9f | 2016-05-20 17:30:07 +0300 | [diff] [blame] | 65 | * @param array $array |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 66 | * @param mixed $column_key |
| 67 | * @param mixed $index_key |
| 68 | * @return array |
| 69 | */ |
| 70 | function array_column(array $array, $column_key, $index_key = NULL) |
| 71 | { |
| 72 | if ( ! in_array($type = gettype($column_key), array('integer', 'string', 'NULL'), TRUE)) |
| 73 | { |
| 74 | if ($type === 'double') |
| 75 | { |
| 76 | $column_key = (int) $column_key; |
| 77 | } |
| 78 | elseif ($type === 'object' && method_exists($column_key, '__toString')) |
| 79 | { |
| 80 | $column_key = (string) $column_key; |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING); |
| 85 | return FALSE; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | if ( ! in_array($type = gettype($index_key), array('integer', 'string', 'NULL'), TRUE)) |
| 90 | { |
| 91 | if ($type === 'double') |
| 92 | { |
| 93 | $index_key = (int) $index_key; |
| 94 | } |
| 95 | elseif ($type === 'object' && method_exists($index_key, '__toString')) |
| 96 | { |
| 97 | $index_key = (string) $index_key; |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING); |
| 102 | return FALSE; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | $result = array(); |
| 107 | foreach ($array as &$a) |
| 108 | { |
| 109 | if ($column_key === NULL) |
| 110 | { |
| 111 | $value = $a; |
| 112 | } |
| 113 | elseif (is_array($a) && array_key_exists($column_key, $a)) |
| 114 | { |
| 115 | $value = $a[$column_key]; |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | continue; |
| 120 | } |
| 121 | |
| 122 | if ($index_key === NULL OR ! array_key_exists($index_key, $a)) |
| 123 | { |
| 124 | $result[] = $value; |
| 125 | } |
| 126 | else |
| 127 | { |
| 128 | $result[$a[$index_key]] = $value; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | return $result; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // ------------------------------------------------------------------------ |
| 137 | |
Andrey Andreev | 5b3fe7c | 2014-07-07 10:55:53 +0300 | [diff] [blame] | 138 | if (is_php('5.4')) |
| 139 | { |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | // ------------------------------------------------------------------------ |
| 144 | |
| 145 | if ( ! function_exists('hex2bin')) |
| 146 | { |
| 147 | /** |
| 148 | * hex2bin() |
| 149 | * |
| 150 | * @link http://php.net/hex2bin |
| 151 | * @param string $data |
| 152 | * @return string |
| 153 | */ |
| 154 | function hex2bin($data) |
| 155 | { |
Andrey Andreev | fa1ca8b | 2016-08-22 14:13:54 +0300 | [diff] [blame] | 156 | if (in_array($type = gettype($data), array('array', 'double', 'object', 'resource'), TRUE)) |
Andrey Andreev | 5b3fe7c | 2014-07-07 10:55:53 +0300 | [diff] [blame] | 157 | { |
| 158 | if ($type === 'object' && method_exists($data, '__toString')) |
| 159 | { |
| 160 | $data = (string) $data; |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | trigger_error('hex2bin() expects parameter 1 to be string, '.$type.' given', E_USER_WARNING); |
| 165 | return NULL; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | if (strlen($data) % 2 !== 0) |
| 170 | { |
| 171 | trigger_error('Hexadecimal input string must have an even length', E_USER_WARNING); |
| 172 | return FALSE; |
| 173 | } |
| 174 | elseif ( ! preg_match('/^[0-9a-f]*$/i', $data)) |
| 175 | { |
| 176 | trigger_error('Input string must be hexadecimal string', E_USER_WARNING); |
| 177 | return FALSE; |
| 178 | } |
| 179 | |
| 180 | return pack('H*', $data); |
| 181 | } |
| 182 | } |