Skip to content

Commit

Permalink
Merge pull request #1 from codeigniter4/develop
Browse files Browse the repository at this point in the history
Develop branch update
  • Loading branch information
atishhamte authored Apr 19, 2019
2 parents d2465a8 + abe469b commit 068d257
Show file tree
Hide file tree
Showing 25 changed files with 783 additions and 54 deletions.
11 changes: 9 additions & 2 deletions system/Config/BaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,15 @@ protected function registerProperties()

if (! static::$didDiscovery)
{
$locator = \Config\Services::locator();
static::$registrars = $locator->search('Config/Registrar.php');
$locator = \Config\Services::locator();
$registrarsFiles = $locator->search('Config/Registrar.php');

foreach ($registrarsFiles as $file)
{
$className = $locator->getClassname($file);
static::$registrars[] = new $className();
}

static::$didDiscovery = true;
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ protected function _like($field, string $match = '', string $type = 'AND ', stri
*
* @return string $like_statement
*/
public function _like_statement(string $prefix = null, string $column, string $not = null, string $bind, bool $insensitiveSearch = false): string
protected function _like_statement(string $prefix = null, string $column, string $not = null, string $bind, bool $insensitiveSearch = false): string
{
$like_statement = "{$prefix} {$column} {$not} LIKE :{$bind}:";

Expand Down
16 changes: 8 additions & 8 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ public function protectIdentifiers($item, bool $prefixSingle = false, bool $prot
*
* This function escapes column and table names
*
* @param mixed
* @param mixed $item
*
* @return mixed
*/
Expand Down Expand Up @@ -1442,7 +1442,7 @@ public function escapeString($str, bool $like = false)
* specific escaping for LIKE conditions
*
* @param string|string[]
* @return mixed
* @return string|string[]
*/
public function escapeLikeString($str)
{
Expand Down Expand Up @@ -1507,19 +1507,19 @@ public function callFunction(string $functionName, ...$params): bool
/**
* Returns an array of table names
*
* @param boolean $constrain_by_prefix = FALSE
* @param boolean $constrainByPrefix = FALSE
* @return boolean|array
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function listTables(bool $constrain_by_prefix = false)
public function listTables(bool $constrainByPrefix = false)
{
// Is there a cached result?
if (isset($this->dataCache['table_names']) && $this->dataCache['table_names'])
{
return $this->dataCache['table_names'];
}

if (false === ($sql = $this->_listTables($constrain_by_prefix)))
if (false === ($sql = $this->_listTables($constrainByPrefix)))
{
if ($this->DBDebug)
{
Expand Down Expand Up @@ -1567,12 +1567,12 @@ public function listTables(bool $constrain_by_prefix = false)
/**
* Determine if a particular table exists
*
* @param string $table_name
* @param string $tableName
* @return boolean
*/
public function tableExists(string $table_name): bool
public function tableExists(string $tableName): bool
{
return in_array($this->protectIdentifiers($table_name, true, false, false), $this->listTables());
return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables());
}

//--------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar/Collectors/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function setFiles(int $current, int $limit = 20)
if (json_last_error() === JSON_ERROR_NONE)
{
preg_match_all('/\d+/', $filename, $time);
$time = (int)$time[0][0];
$time = (int)end($time[0]);

// Debugbar files shown in History Collector
$files[] = [
Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar/Collectors/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function display(): array
$params[] = [
'name' => $param->getName(),
'value' => $router->params()[$key] ??
'<empty>&nbsp| default: ' . var_export($param->getDefaultValue(), true),
'<empty>&nbsp| default: ' . var_export($param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, true),
];
}

Expand Down
2 changes: 2 additions & 0 deletions system/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@

namespace CodeIgniter;

use CodeIgniter\Exceptions\EntityException;
use CodeIgniter\I18n\Time;
use CodeIgniter\Exceptions\CastException;
use CodeIgniter\Exceptions\EntityException;

/**
* Entity encapsulation, for use with CodeIgniter\Model
Expand Down
2 changes: 2 additions & 0 deletions system/Language/en/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'alpha_space' => 'The {field} field may only contain alphabetical characters and spaces.',
'decimal' => 'The {field} field must contain a decimal number.',
'differs' => 'The {field} field must differ from the {param} field.',
'equals' => 'The {field} field must be exactly: {param}.',
'exact_length' => 'The {field} field must be exactly {param} characters in length.',
'greater_than' => 'The {field} field must contain a number greater than {param}.',
'greater_than_equal_to' => 'The {field} field must contain a number greater than or equal to {param}.',
Expand All @@ -43,6 +44,7 @@
'matches' => 'The {field} field does not match the {param} field.',
'max_length' => 'The {field} field cannot exceed {param} characters in length.',
'min_length' => 'The {field} field must be at least {param} characters in length.',
'not_equals' => 'The {field} field cannot be: {param}.',
'numeric' => 'The {field} field must contain only numbers.',
'regex_match' => 'The {field} field is not in the correct format.',
'required' => 'The {field} field is required.',
Expand Down
26 changes: 13 additions & 13 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,11 @@ public function insert($data = null, bool $returnID = true)
$this->tempData = [];
}

if (empty($data))
{
throw DataException::forEmptyDataset('insert');
}

// If $data is using a custom class with public or protected
// properties representing the table elements, we need to grab
// them as an array.
Expand Down Expand Up @@ -668,11 +673,6 @@ public function insert($data = null, bool $returnID = true)

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

if (empty($data))
{
throw DataException::forEmptyDataset('insert');
}

// Must use the set() method to ensure objects get converted to arrays
$result = $this->builder()
->set($data['data'], '', $escape)
Expand Down Expand Up @@ -749,6 +749,11 @@ public function update($id = null, $data = null): bool
$this->tempData = [];
}

if (empty($data))
{
throw DataException::forEmptyDataset('update');
}

// If $data is using a custom class with public or protected
// properties representing the table elements, we need to grab
// them as an array.
Expand Down Expand Up @@ -790,11 +795,6 @@ public function update($id = null, $data = null): bool

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

if (empty($data))
{
throw DataException::forEmptyDataset('update');
}

$builder = $this->builder();

if ($id)
Expand Down Expand Up @@ -956,9 +956,9 @@ public function onlyDeleted()
* @param null $data
* @param boolean $returnSQL
*
* @return boolean TRUE on success, FALSE on failure
* @return mixed
*/
public function replace($data = null, bool $returnSQL = false): bool
public function replace($data = null, bool $returnSQL = false)
{
// Validate data before saving.
if (! empty($data) && $this->skipValidation === false)
Expand Down Expand Up @@ -1317,7 +1317,7 @@ public function setValidationMessage(string $field, array $fieldMessages)
* Validate the data against the validation rules (or the validation group)
* specified in the class property, $validationRules.
*
* @param array $data
* @param array|object $data
*
* @return boolean
*/
Expand Down
30 changes: 30 additions & 0 deletions system/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ public function differs(string $str = null, string $field, array $data): bool

//--------------------------------------------------------------------

/**
* Equals the static value provided.
*
* @param string $str
* @param string $val
*
* @return boolean
*/
public function equals(string $str = null, string $val): bool
{
return $str === $val;
}

//--------------------------------------------------------------------

/**
* Returns true if $str is $val characters long.
* $val = "5" (one) | "5,8,12" (multiple values)
Expand Down Expand Up @@ -261,6 +276,21 @@ public function min_length(string $str = null, string $val, array $data): bool

//--------------------------------------------------------------------

/**
* Does not equal the static value provided.
*
* @param string $str
* @param string $val
*
* @return boolean
*/
public function not_equals(string $str = null, string $val): bool
{
return $str !== $val;
}

//--------------------------------------------------------------------

/**
* Required
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public function up()
'constraint' => 1,
'default' => '0',
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->createTable('user', true);
Expand All @@ -50,9 +58,20 @@ public function up()
'type' => 'TEXT',
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
'deleted' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => '0',
],
'created_at' => [
'type' => 'INTEGER',
'constraint' => 11,
'null' => true,
],
'updated_at' => [
'type' => 'INTEGER',
'constraint' => 11,
'null' => true,
],
]);
$this->forge->addKey('id', true);
Expand Down Expand Up @@ -85,6 +104,14 @@ public function up()
'type' => 'VARCHAR',
'constraint' => 40,
],
'created_at' => [
'type' => 'DATE',
'null' => true,
],
'updated_at' => [
'type' => 'DATE',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->createTable('empty', true);
Expand Down
4 changes: 3 additions & 1 deletion tests/_support/Models/EntityModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class EntityModel extends Model

protected $useSoftDeletes = false;

protected $dateFormat = 'datetime';
protected $dateFormat = 'int';

protected $deletedField = 'deleted';

protected $allowedFields = [
'name',
Expand Down
2 changes: 1 addition & 1 deletion tests/_support/Models/EventModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EventModel extends Model

protected $useSoftDeletes = false;

protected $dateFormat = 'integer';
protected $dateFormat = 'datetime';

protected $allowedFields = [
'name',
Expand Down
6 changes: 5 additions & 1 deletion tests/_support/Models/JobModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ class JobModel extends Model

protected $useSoftDeletes = false;

protected $dateFormat = 'integer';
protected $dateFormat = 'int';

protected $allowedFields = [
'name',
'description',
];

public $name = '';

public $description = '';
}
2 changes: 1 addition & 1 deletion tests/_support/Models/SecondaryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SecondaryModel extends Model

protected $useSoftDeletes = false;

protected $dateFormat = 'integer';
protected $dateFormat = 'int';

protected $allowedFields = [
'key',
Expand Down
2 changes: 2 additions & 0 deletions tests/_support/Models/SimpleEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class SimpleEntity extends Entity
protected $id;
protected $name;
protected $description;
protected $deleted;
protected $created_at;
protected $updated_at;

protected $_options = [
'datamap' => [],
Expand Down
8 changes: 7 additions & 1 deletion tests/_support/Models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ class UserModel extends Model

protected $useSoftDeletes = true;

protected $dateFormat = 'integer';
protected $dateFormat = 'datetime';

public $name = '';

public $email = '';

public $country = '';
}
2 changes: 1 addition & 1 deletion tests/_support/Models/ValidErrorsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ValidErrorsModel extends Model

protected $useSoftDeletes = false;

protected $dateFormat = 'integer';
protected $dateFormat = 'int';

protected $allowedFields = [
'name',
Expand Down
2 changes: 1 addition & 1 deletion tests/_support/Models/ValidModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ValidModel extends Model

protected $useSoftDeletes = false;

protected $dateFormat = 'integer';
protected $dateFormat = 'int';

protected $allowedFields = [
'name',
Expand Down
Loading

0 comments on commit 068d257

Please sign in to comment.