Skip to content

Commit 068d257

Browse files
authored
Merge pull request #1 from codeigniter4/develop
Develop branch update
2 parents d2465a8 + abe469b commit 068d257

File tree

25 files changed

+783
-54
lines changed

25 files changed

+783
-54
lines changed

system/Config/BaseConfig.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,15 @@ protected function registerProperties()
181181

182182
if (! static::$didDiscovery)
183183
{
184-
$locator = \Config\Services::locator();
185-
static::$registrars = $locator->search('Config/Registrar.php');
184+
$locator = \Config\Services::locator();
185+
$registrarsFiles = $locator->search('Config/Registrar.php');
186+
187+
foreach ($registrarsFiles as $file)
188+
{
189+
$className = $locator->getClassname($file);
190+
static::$registrars[] = new $className();
191+
}
192+
186193
static::$didDiscovery = true;
187194
}
188195

system/Database/BaseBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ protected function _like($field, string $match = '', string $type = 'AND ', stri
10241024
*
10251025
* @return string $like_statement
10261026
*/
1027-
public function _like_statement(string $prefix = null, string $column, string $not = null, string $bind, bool $insensitiveSearch = false): string
1027+
protected function _like_statement(string $prefix = null, string $column, string $not = null, string $bind, bool $insensitiveSearch = false): string
10281028
{
10291029
$like_statement = "{$prefix} {$column} {$not} LIKE :{$bind}:";
10301030

system/Database/BaseConnection.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ public function protectIdentifiers($item, bool $prefixSingle = false, bool $prot
12471247
*
12481248
* This function escapes column and table names
12491249
*
1250-
* @param mixed
1250+
* @param mixed $item
12511251
*
12521252
* @return mixed
12531253
*/
@@ -1442,7 +1442,7 @@ public function escapeString($str, bool $like = false)
14421442
* specific escaping for LIKE conditions
14431443
*
14441444
* @param string|string[]
1445-
* @return mixed
1445+
* @return string|string[]
14461446
*/
14471447
public function escapeLikeString($str)
14481448
{
@@ -1507,19 +1507,19 @@ public function callFunction(string $functionName, ...$params): bool
15071507
/**
15081508
* Returns an array of table names
15091509
*
1510-
* @param boolean $constrain_by_prefix = FALSE
1510+
* @param boolean $constrainByPrefix = FALSE
15111511
* @return boolean|array
15121512
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
15131513
*/
1514-
public function listTables(bool $constrain_by_prefix = false)
1514+
public function listTables(bool $constrainByPrefix = false)
15151515
{
15161516
// Is there a cached result?
15171517
if (isset($this->dataCache['table_names']) && $this->dataCache['table_names'])
15181518
{
15191519
return $this->dataCache['table_names'];
15201520
}
15211521

1522-
if (false === ($sql = $this->_listTables($constrain_by_prefix)))
1522+
if (false === ($sql = $this->_listTables($constrainByPrefix)))
15231523
{
15241524
if ($this->DBDebug)
15251525
{
@@ -1567,12 +1567,12 @@ public function listTables(bool $constrain_by_prefix = false)
15671567
/**
15681568
* Determine if a particular table exists
15691569
*
1570-
* @param string $table_name
1570+
* @param string $tableName
15711571
* @return boolean
15721572
*/
1573-
public function tableExists(string $table_name): bool
1573+
public function tableExists(string $tableName): bool
15741574
{
1575-
return in_array($this->protectIdentifiers($table_name, true, false, false), $this->listTables());
1575+
return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables());
15761576
}
15771577

15781578
//--------------------------------------------------------------------

system/Debug/Toolbar/Collectors/History.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function setFiles(int $current, int $limit = 20)
111111
if (json_last_error() === JSON_ERROR_NONE)
112112
{
113113
preg_match_all('/\d+/', $filename, $time);
114-
$time = (int)$time[0][0];
114+
$time = (int)end($time[0]);
115115

116116
// Debugbar files shown in History Collector
117117
$files[] = [

system/Debug/Toolbar/Collectors/Routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function display(): array
9797
$params[] = [
9898
'name' => $param->getName(),
9999
'value' => $router->params()[$key] ??
100-
'<empty>&nbsp| default: ' . var_export($param->getDefaultValue(), true),
100+
'<empty>&nbsp| default: ' . var_export($param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, true),
101101
];
102102
}
103103

system/Entity.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838

3939
namespace CodeIgniter;
4040

41+
use CodeIgniter\Exceptions\EntityException;
4142
use CodeIgniter\I18n\Time;
4243
use CodeIgniter\Exceptions\CastException;
44+
use CodeIgniter\Exceptions\EntityException;
4345

4446
/**
4547
* Entity encapsulation, for use with CodeIgniter\Model

system/Language/en/Validation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
'alpha_space' => 'The {field} field may only contain alphabetical characters and spaces.',
3131
'decimal' => 'The {field} field must contain a decimal number.',
3232
'differs' => 'The {field} field must differ from the {param} field.',
33+
'equals' => 'The {field} field must be exactly: {param}.',
3334
'exact_length' => 'The {field} field must be exactly {param} characters in length.',
3435
'greater_than' => 'The {field} field must contain a number greater than {param}.',
3536
'greater_than_equal_to' => 'The {field} field must contain a number greater than or equal to {param}.',
@@ -43,6 +44,7 @@
4344
'matches' => 'The {field} field does not match the {param} field.',
4445
'max_length' => 'The {field} field cannot exceed {param} characters in length.',
4546
'min_length' => 'The {field} field must be at least {param} characters in length.',
47+
'not_equals' => 'The {field} field cannot be: {param}.',
4648
'numeric' => 'The {field} field must contain only numbers.',
4749
'regex_match' => 'The {field} field is not in the correct format.',
4850
'required' => 'The {field} field is required.',

system/Model.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ public function insert($data = null, bool $returnID = true)
619619
$this->tempData = [];
620620
}
621621

622+
if (empty($data))
623+
{
624+
throw DataException::forEmptyDataset('insert');
625+
}
626+
622627
// If $data is using a custom class with public or protected
623628
// properties representing the table elements, we need to grab
624629
// them as an array.
@@ -668,11 +673,6 @@ public function insert($data = null, bool $returnID = true)
668673

669674
$data = $this->trigger('beforeInsert', ['data' => $data]);
670675

671-
if (empty($data))
672-
{
673-
throw DataException::forEmptyDataset('insert');
674-
}
675-
676676
// Must use the set() method to ensure objects get converted to arrays
677677
$result = $this->builder()
678678
->set($data['data'], '', $escape)
@@ -749,6 +749,11 @@ public function update($id = null, $data = null): bool
749749
$this->tempData = [];
750750
}
751751

752+
if (empty($data))
753+
{
754+
throw DataException::forEmptyDataset('update');
755+
}
756+
752757
// If $data is using a custom class with public or protected
753758
// properties representing the table elements, we need to grab
754759
// them as an array.
@@ -790,11 +795,6 @@ public function update($id = null, $data = null): bool
790795

791796
$data = $this->trigger('beforeUpdate', ['id' => $id, 'data' => $data]);
792797

793-
if (empty($data))
794-
{
795-
throw DataException::forEmptyDataset('update');
796-
}
797-
798798
$builder = $this->builder();
799799

800800
if ($id)
@@ -956,9 +956,9 @@ public function onlyDeleted()
956956
* @param null $data
957957
* @param boolean $returnSQL
958958
*
959-
* @return boolean TRUE on success, FALSE on failure
959+
* @return mixed
960960
*/
961-
public function replace($data = null, bool $returnSQL = false): bool
961+
public function replace($data = null, bool $returnSQL = false)
962962
{
963963
// Validate data before saving.
964964
if (! empty($data) && $this->skipValidation === false)
@@ -1317,7 +1317,7 @@ public function setValidationMessage(string $field, array $fieldMessages)
13171317
* Validate the data against the validation rules (or the validation group)
13181318
* specified in the class property, $validationRules.
13191319
*
1320-
* @param array $data
1320+
* @param array|object $data
13211321
*
13221322
* @return boolean
13231323
*/

system/Validation/Rules.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ public function differs(string $str = null, string $field, array $data): bool
6565

6666
//--------------------------------------------------------------------
6767

68+
/**
69+
* Equals the static value provided.
70+
*
71+
* @param string $str
72+
* @param string $val
73+
*
74+
* @return boolean
75+
*/
76+
public function equals(string $str = null, string $val): bool
77+
{
78+
return $str === $val;
79+
}
80+
81+
//--------------------------------------------------------------------
82+
6883
/**
6984
* Returns true if $str is $val characters long.
7085
* $val = "5" (one) | "5,8,12" (multiple values)
@@ -261,6 +276,21 @@ public function min_length(string $str = null, string $val, array $data): bool
261276

262277
//--------------------------------------------------------------------
263278

279+
/**
280+
* Does not equal the static value provided.
281+
*
282+
* @param string $str
283+
* @param string $val
284+
*
285+
* @return boolean
286+
*/
287+
public function not_equals(string $str = null, string $val): bool
288+
{
289+
return $str !== $val;
290+
}
291+
292+
//--------------------------------------------------------------------
293+
264294
/**
265295
* Required
266296
*

tests/_support/Database/Migrations/20160428212500_Create_test_tables.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public function up()
3131
'constraint' => 1,
3232
'default' => '0',
3333
],
34+
'created_at' => [
35+
'type' => 'DATETIME',
36+
'null' => true,
37+
],
38+
'updated_at' => [
39+
'type' => 'DATETIME',
40+
'null' => true,
41+
],
3442
]);
3543
$this->forge->addKey('id', true);
3644
$this->forge->createTable('user', true);
@@ -50,9 +58,20 @@ public function up()
5058
'type' => 'TEXT',
5159
'null' => true,
5260
],
53-
'created_at' => [
54-
'type' => 'DATETIME',
55-
'null' => true,
61+
'deleted' => [
62+
'type' => 'TINYINT',
63+
'constraint' => 1,
64+
'default' => '0',
65+
],
66+
'created_at' => [
67+
'type' => 'INTEGER',
68+
'constraint' => 11,
69+
'null' => true,
70+
],
71+
'updated_at' => [
72+
'type' => 'INTEGER',
73+
'constraint' => 11,
74+
'null' => true,
5675
],
5776
]);
5877
$this->forge->addKey('id', true);
@@ -85,6 +104,14 @@ public function up()
85104
'type' => 'VARCHAR',
86105
'constraint' => 40,
87106
],
107+
'created_at' => [
108+
'type' => 'DATE',
109+
'null' => true,
110+
],
111+
'updated_at' => [
112+
'type' => 'DATE',
113+
'null' => true,
114+
],
88115
]);
89116
$this->forge->addKey('id', true);
90117
$this->forge->createTable('empty', true);

tests/_support/Models/EntityModel.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class EntityModel extends Model
1010

1111
protected $useSoftDeletes = false;
1212

13-
protected $dateFormat = 'datetime';
13+
protected $dateFormat = 'int';
14+
15+
protected $deletedField = 'deleted';
1416

1517
protected $allowedFields = [
1618
'name',

tests/_support/Models/EventModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class EventModel extends Model
1010

1111
protected $useSoftDeletes = false;
1212

13-
protected $dateFormat = 'integer';
13+
protected $dateFormat = 'datetime';
1414

1515
protected $allowedFields = [
1616
'name',

tests/_support/Models/JobModel.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ class JobModel extends Model
1010

1111
protected $useSoftDeletes = false;
1212

13-
protected $dateFormat = 'integer';
13+
protected $dateFormat = 'int';
1414

1515
protected $allowedFields = [
1616
'name',
1717
'description',
1818
];
19+
20+
public $name = '';
21+
22+
public $description = '';
1923
}

tests/_support/Models/SecondaryModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SecondaryModel extends Model
1212

1313
protected $useSoftDeletes = false;
1414

15-
protected $dateFormat = 'integer';
15+
protected $dateFormat = 'int';
1616

1717
protected $allowedFields = [
1818
'key',

tests/_support/Models/SimpleEntity.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class SimpleEntity extends Entity
1515
protected $id;
1616
protected $name;
1717
protected $description;
18+
protected $deleted;
1819
protected $created_at;
20+
protected $updated_at;
1921

2022
protected $_options = [
2123
'datamap' => [],

tests/_support/Models/UserModel.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,11 @@ class UserModel extends Model
1717

1818
protected $useSoftDeletes = true;
1919

20-
protected $dateFormat = 'integer';
20+
protected $dateFormat = 'datetime';
21+
22+
public $name = '';
23+
24+
public $email = '';
25+
26+
public $country = '';
2127
}

tests/_support/Models/ValidErrorsModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ValidErrorsModel extends Model
1010

1111
protected $useSoftDeletes = false;
1212

13-
protected $dateFormat = 'integer';
13+
protected $dateFormat = 'int';
1414

1515
protected $allowedFields = [
1616
'name',

tests/_support/Models/ValidModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ValidModel extends Model
1010

1111
protected $useSoftDeletes = false;
1212

13-
protected $dateFormat = 'integer';
13+
protected $dateFormat = 'int';
1414

1515
protected $allowedFields = [
1616
'name',

0 commit comments

Comments
 (0)