CodeIgniter 3.1.11 -> 3.4.5 (pocketarc fork) en PHP 8.3-fixes

- system/ vervangen door CodeIgniter 3.4.5 (pocketarc/codeigniter, PHP 8.2-8.5 compatibel)
- config.php, mimes.php, user_agents.php en error-views bijgewerkt naar 3.4.5
- composer.json: php-constraint "^7.4 || ^8.0" zodat composer install op 8.3 werkt
- PHP 8-fatals opgelost: count()/array-functies op FALSE/null, rekenen met lege
  strings, delen door nul, property zetten op FALSE, curly-brace string offsets,
  ongedefinieerde constanten, foute curl_setopt in Phantom_model::create_img
- dynamic properties gedeclareerd in libraries, optionele parameters voor verplichte opgelost
- vergelijkingen waar '' == 0 in PHP 8 anders uitvalt gecast naar (int)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 09:34:46 +02:00
co-authored by Claude Opus 5.5
parent c6afbb01f2
commit 172fcf566c
284 changed files with 3497 additions and 3718 deletions
+77 -46
View File
@@ -6,7 +6,7 @@
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2019, British Columbia Institute of Technology
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -30,6 +30,7 @@
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
@@ -44,7 +45,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
* @subpackage Libraries
* @category Validation
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/libraries/form_validation.html
* @link https://codeigniter.com/userguide3/libraries/form_validation.html
*/
class CI_Form_validation {
@@ -105,8 +106,9 @@ class CI_Form_validation {
protected $error_string = '';
/**
* Whether the form data has been validated as safe
* Whether the form data has been through validation and had errors
*
* @deprecated 3.0.6
* @var bool
*/
protected $_safe_form_data = FALSE;
@@ -164,7 +166,7 @@ class CI_Form_validation {
* @param array $errors
* @return CI_Form_validation
*/
public function set_rules($field, $label = '', $rules = array(), $errors = array())
public function set_rules($field, $label = null, $rules = null, $errors = array())
{
// No reason to set rules if we have no POST data
// or a validation array has not been specified
@@ -197,18 +199,22 @@ class CI_Form_validation {
return $this;
}
elseif ( ! isset($rules))
{
throw new BadMethodCallException('Form_validation: set_rules() called without a $rules parameter');
}
// No fields or no rules? Nothing to do...
if ( ! is_string($field) OR $field === '' OR empty($rules))
{
return $this;
throw new RuntimeException('Form_validation: set_rules() called with an empty $rules parameter');
}
elseif ( ! is_array($rules))
{
// BC: Convert pipe-separated rules string to an array
if ( ! is_string($rules))
{
return $this;
throw new InvalidArgumentException('Form_validation: set_rules() expect $rules to be string or array; '.gettype($rules).' given');
}
$rules = preg_split('/\|(?![^\[]*\])/', $rules);
@@ -410,10 +416,11 @@ class CI_Form_validation {
*
* This function does all the work.
*
* @param string $group
* @param string $config
* @param array $data
* @return bool
*/
public function run($group = '')
public function run($config = NULL, &$data = NULL)
{
$validation_array = empty($this->validation_data)
? $_POST
@@ -424,19 +431,19 @@ class CI_Form_validation {
if (count($this->_field_data) === 0)
{
// No validation rules? We're done...
if (count($this->_config_rules) === 0)
if (empty($this->_config_rules))
{
return FALSE;
}
if (empty($group))
if (empty($config))
{
// Is there a validation rule for the particular URI being accessed?
$group = trim($this->CI->uri->ruri_string(), '/');
isset($this->_config_rules[$group]) OR $group = $this->CI->router->class.'/'.$this->CI->router->method;
$config = trim($this->CI->uri->ruri_string(), '/');
isset($this->_config_rules[$config]) OR $config = $this->CI->router->class.'/'.$this->CI->router->method;
}
$this->set_rules(isset($this->_config_rules[$group]) ? $this->_config_rules[$group] : $this->_config_rules);
$this->set_rules(isset($this->_config_rules[$config]) ? $this->_config_rules[$config] : $this->_config_rules);
// Were we able to set the rules correctly?
if (count($this->_field_data) === 0)
@@ -478,17 +485,23 @@ class CI_Form_validation {
$this->_execute($row, $row['rules'], $row['postdata']);
}
// Did we end up with any errors?
$total_errors = count($this->_error_array);
if ($total_errors > 0)
if ( ! empty($this->_error_array))
{
$this->_safe_form_data = TRUE;
return FALSE;
}
// Now we need to re-set the POST data with the new, processed data
empty($this->validation_data) && $this->_reset_post_array();
// Fill $data if requested, otherwise modify $_POST, as long as
// set_data() wasn't used (yea, I know it sounds confusing)
if (func_num_args() >= 2)
{
$data = empty($this->validation_data) ? $_POST : $this->validation_data;
$this->_reset_data_array($data);
return TRUE;
}
return ($total_errors === 0);
empty($this->validation_data) && $this->_reset_data_array($_POST);
return TRUE;
}
// --------------------------------------------------------------------
@@ -576,7 +589,7 @@ class CI_Form_validation {
*
* @return void
*/
protected function _reset_post_array()
protected function _reset_data_array(&$data)
{
foreach ($this->_field_data as $field => $row)
{
@@ -584,27 +597,26 @@ class CI_Form_validation {
{
if ($row['is_array'] === FALSE)
{
isset($_POST[$field]) && $_POST[$field] = is_array($row['postdata']) ? NULL : $row['postdata'];
isset($data[$field]) && $data[$field] = is_array($row['postdata']) ? NULL : $row['postdata'];
}
else
{
// start with a reference
$post_ref =& $_POST;
$data_ref =& $data;
// before we assign values, make a reference to the right POST key
if (count($row['keys']) === 1)
{
$post_ref =& $post_ref[current($row['keys'])];
$data_ref =& $data[current($row['keys'])];
}
else
{
foreach ($row['keys'] as $val)
{
$post_ref =& $post_ref[$val];
$data_ref =& $data_ref[$val];
}
}
$post_ref = $row['postdata'];
$data_ref = $row['postdata'];
}
}
}
@@ -623,11 +635,13 @@ class CI_Form_validation {
*/
protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)
{
$allow_arrays = in_array('is_array', $rules, TRUE);
// If the $_POST data is an array we will run a recursive call
//
// Note: We MUST check if the array is empty or not!
// Otherwise empty arrays will always pass validation.
if (is_array($postdata) && ! empty($postdata))
if ($allow_arrays === FALSE && is_array($postdata) && ! empty($postdata))
{
foreach ($postdata as $key => $val)
{
@@ -656,14 +670,16 @@ class CI_Form_validation {
$postdata = $this->_field_data[$row['field']]['postdata'][$cycles];
$_in_array = TRUE;
}
// If we get an array field, but it's not expected - then it is most likely
// somebody messing with the form on the client side, so we'll just consider
// it an empty field
elseif ($allow_arrays === FALSE && is_array($this->_field_data[$row['field']]['postdata']))
{
$postdata = NULL;
}
else
{
// If we get an array field, but it's not expected - then it is most likely
// somebody messing with the form on the client side, so we'll just consider
// it an empty field
$postdata = is_array($this->_field_data[$row['field']]['postdata'])
? NULL
: $this->_field_data[$row['field']]['postdata'];
$postdata = $this->_field_data[$row['field']]['postdata'];
}
// Is the rule a callback?
@@ -698,7 +714,7 @@ class CI_Form_validation {
// Ignore empty, non-required inputs with a few exceptions ...
if (
($postdata === NULL OR $postdata === '')
($postdata === NULL OR ($allow_arrays === FALSE && $postdata === ''))
&& $callback === FALSE
&& $callable === FALSE
&& ! in_array($rule, array('required', 'isset', 'matches'), TRUE)
@@ -845,11 +861,6 @@ class CI_Form_validation {
{
return $line;
}
// DEPRECATED support for non-prefixed keys, lang file again
elseif (FALSE !== ($line = $this->CI->lang->line($rule, FALSE)))
{
return $line;
}
return $this->CI->lang->line('form_validation_error_message_not_set').'('.$rule.')';
}
@@ -1056,7 +1067,7 @@ class CI_Form_validation {
{
return is_array($str)
? (empty($str) === FALSE)
: (trim($str) !== '');
: (trim((string) $str) !== '');
}
// --------------------------------------------------------------------
@@ -1293,6 +1304,31 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
* Validate MAC address
*
* @param string $mac
* @return bool
*/
public function valid_mac($mac)
{
if ( ! is_php('5.5'))
{
// Most common format, with either dash or colon delimiters
if (preg_match('#\A[0-9a-f]{2}(?<delimiter>[:-])([0-9a-f]{2}(?P=delimiter)){4}[0-9a-f]{2}\z#i', $mac))
{
return TRUE;
}
// The less common format; e.g. 0123.4567.89ab
return (bool) preg_match('#((\A|\.)[0-9a-f]{4}){3}\z#i', $mac);
}
return (bool) filter_var($mac, FILTER_VALIDATE_MAC);
}
// --------------------------------------------------------------------
/**
* Alpha
*
@@ -1537,12 +1573,7 @@ class CI_Form_validation {
*/
public function prep_url($str = '')
{
if ($str === 'http://' OR $str === '')
{
return '';
}
if (strpos($str, 'http://') !== 0 && strpos($str, 'https://') !== 0)
if ($str !== '' && stripos($str, 'http://') !== 0 && stripos($str, 'https://') !== 0)
{
return 'http://'.$str;
}