PageRenderTime 44ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/system/core/compat/standard.php

https://gitlab.com/strongpapazola/gempabmkg
PHP | 183 lines | 102 code | 15 blank | 66 comment | 17 complexity | 224d7eb7bee9c563aab964bb5ee2025f MD5 | raw file
  1. <?php
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP
  6. *
  7. * This content is released under the MIT License (MIT)
  8. *
  9. * Copyright (c) 2019 - 2022, CodeIgniter Foundation
  10. *
  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:
  17. *
  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
  31. * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
  32. * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
  33. * @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
  34. * @license https://opensource.org/licenses/MIT MIT License
  35. * @link https://codeigniter.com
  36. * @since Version 3.0.0
  37. * @filesource
  38. */
  39. defined('BASEPATH') OR exit('No direct script access allowed');
  40. /**
  41. * PHP ext/standard compatibility package
  42. *
  43. * @package CodeIgniter
  44. * @subpackage CodeIgniter
  45. * @category Compatibility
  46. * @author Andrey Andreev
  47. * @link https://codeigniter.com/userguide3/
  48. */
  49. // ------------------------------------------------------------------------
  50. if (is_php('5.5'))
  51. {
  52. return;
  53. }
  54. // ------------------------------------------------------------------------
  55. if ( ! function_exists('array_column'))
  56. {
  57. /**
  58. * array_column()
  59. *
  60. * @link http://php.net/array_column
  61. * @param array $array
  62. * @param mixed $column_key
  63. * @param mixed $index_key
  64. * @return array
  65. */
  66. function array_column(array $array, $column_key, $index_key = NULL)
  67. {
  68. if ( ! in_array($type = gettype($column_key), array('integer', 'string', 'NULL'), TRUE))
  69. {
  70. if ($type === 'double')
  71. {
  72. $column_key = (int) $column_key;
  73. }
  74. elseif ($type === 'object' && method_exists($column_key, '__toString'))
  75. {
  76. $column_key = (string) $column_key;
  77. }
  78. else
  79. {
  80. trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
  81. return FALSE;
  82. }
  83. }
  84. if ( ! in_array($type = gettype($index_key), array('integer', 'string', 'NULL'), TRUE))
  85. {
  86. if ($type === 'double')
  87. {
  88. $index_key = (int) $index_key;
  89. }
  90. elseif ($type === 'object' && method_exists($index_key, '__toString'))
  91. {
  92. $index_key = (string) $index_key;
  93. }
  94. else
  95. {
  96. trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
  97. return FALSE;
  98. }
  99. }
  100. $result = array();
  101. foreach ($array as &$a)
  102. {
  103. if ($column_key === NULL)
  104. {
  105. $value = $a;
  106. }
  107. elseif (is_array($a) && array_key_exists($column_key, $a))
  108. {
  109. $value = $a[$column_key];
  110. }
  111. else
  112. {
  113. continue;
  114. }
  115. if ($index_key === NULL OR ! array_key_exists($index_key, $a))
  116. {
  117. $result[] = $value;
  118. }
  119. else
  120. {
  121. $result[$a[$index_key]] = $value;
  122. }
  123. }
  124. return $result;
  125. }
  126. }
  127. // ------------------------------------------------------------------------
  128. if (is_php('5.4'))
  129. {
  130. return;
  131. }
  132. // ------------------------------------------------------------------------
  133. if ( ! function_exists('hex2bin'))
  134. {
  135. /**
  136. * hex2bin()
  137. *
  138. * @link http://php.net/hex2bin
  139. * @param string $data
  140. * @return string
  141. */
  142. function hex2bin($data)
  143. {
  144. if (in_array($type = gettype($data), array('array', 'double', 'object', 'resource'), TRUE))
  145. {
  146. if ($type === 'object' && method_exists($data, '__toString'))
  147. {
  148. $data = (string) $data;
  149. }
  150. else
  151. {
  152. trigger_error('hex2bin() expects parameter 1 to be string, '.$type.' given', E_USER_WARNING);
  153. return NULL;
  154. }
  155. }
  156. if (strlen($data) % 2 !== 0)
  157. {
  158. trigger_error('Hexadecimal input string must have an even length', E_USER_WARNING);
  159. return FALSE;
  160. }
  161. elseif ( ! preg_match('/^[0-9a-f]*$/i', $data))
  162. {
  163. trigger_error('Input string must be hexadecimal string', E_USER_WARNING);
  164. return FALSE;
  165. }
  166. return pack('H*', $data);
  167. }
  168. }