Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -4,19 +4,18 @@
*
* Provides the Model validation logic.
*
* PHP versions 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Model.Validator
* @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Validation', 'Utility');
@ -40,7 +39,7 @@ class CakeValidationRule {
/**
* Holds whether the record being validated exists in datasource or not
*
* @var boolean
* @var bool
*/
protected $_recordExists = false;
@ -82,7 +81,7 @@ class CakeValidationRule {
/**
* The 'allowEmpty' key
*
* @var boolean
* @var bool
*/
public $allowEmpty = null;
@ -96,7 +95,7 @@ class CakeValidationRule {
/**
* The 'last' key
*
* @var boolean
* @var bool
*/
public $last = true;
@ -119,7 +118,7 @@ class CakeValidationRule {
/**
* Checks if the rule is valid
*
* @return boolean
* @return bool
*/
public function isValid() {
if (!$this->_valid || (is_string($this->_valid) && !empty($this->_valid))) {
@ -132,7 +131,7 @@ class CakeValidationRule {
/**
* Returns whether the field can be left blank according to this rule
*
* @return boolean
* @return bool
*/
public function isEmptyAllowed() {
return $this->skip() || $this->allowEmpty === true;
@ -141,15 +140,14 @@ class CakeValidationRule {
/**
* Checks if the field is required according to the `required` property
*
* @return boolean
* @return bool
*/
public function isRequired() {
if (in_array($this->required, array('create', 'update'), true)) {
if ($this->required === 'create' && !$this->isUpdate() || $this->required === 'update' && $this->isUpdate()) {
return true;
} else {
return false;
}
return false;
}
return $this->required;
@ -158,8 +156,9 @@ class CakeValidationRule {
/**
* Checks whether the field failed the `field should be present` validation
*
* @param array $data data to check rule against
* @return boolean
* @param string $field Field name
* @param array &$data Data to check rule against
* @return bool
*/
public function checkRequired($field, &$data) {
return (
@ -174,8 +173,9 @@ class CakeValidationRule {
/**
* Checks if the allowEmpty key applies
*
* @param array $data data to check rule against
* @return boolean
* @param string $field Field name
* @param array &$data data to check rule against
* @return bool
*/
public function checkEmpty($field, &$data) {
if (empty($data[$field]) && $data[$field] != '0' && $this->allowEmpty === true) {
@ -187,11 +187,11 @@ class CakeValidationRule {
/**
* Checks if the validation rule should be skipped
*
* @return boolean True if the ValidationRule can be skipped
* @return bool True if the ValidationRule can be skipped
*/
public function skip() {
if (!empty($this->on)) {
if ($this->on == 'create' && $this->isUpdate() || $this->on == 'update' && !$this->isUpdate()) {
if ($this->on === 'create' && $this->isUpdate() || $this->on === 'update' && !$this->isUpdate()) {
return true;
}
}
@ -199,10 +199,10 @@ class CakeValidationRule {
}
/**
* Returns whethere this rule should break validation process for associated field
* Returns whether this rule should break validation process for associated field
* after it fails
*
* @return boolean
* @return bool
*/
public function isLast() {
return (bool)$this->last;
@ -239,14 +239,15 @@ class CakeValidationRule {
/**
* Sets the recordExists configuration value for this rule,
* ir refers to wheter the model record it is validating exists
* ir refers to whether the model record it is validating exists
* exists in the collection or not (create or update operation)
*
* If called with no parameters it will return whether this rule
* is configured for update operations or not.
*
* @return boolean
**/
* @param bool $exists Boolean to indicate if records exists
* @return bool
*/
public function isUpdate($exists = null) {
if ($exists === null) {
return $this->_recordExists;
@ -257,7 +258,10 @@ class CakeValidationRule {
/**
* Dispatches the validation rule to the given validator method
*
* @return boolean True if the rule could be dispatched, false otherwise
* @param string $field Field name
* @param array &$data Data array
* @param array &$methods Methods list
* @return bool True if the rule could be dispatched, false otherwise
*/
public function process($field, &$data, &$methods) {
$this->_valid = true;
@ -273,7 +277,7 @@ class CakeValidationRule {
$this->_valid = call_user_func_array(array('Validation', $this->_rule), $this->_ruleParams);
} elseif (is_string($validator['rule'])) {
$this->_valid = preg_match($this->_rule, $data[$field]);
} elseif (Configure::read('debug') > 0) {
} else {
trigger_error(__d('cake_dev', 'Could not find validation handler %s for %s', $this->_rule, $field), E_USER_WARNING);
return false;
}
@ -282,11 +286,11 @@ class CakeValidationRule {
}
/**
* Resets interal state for this rule, by default it will become valid
* Resets internal state for this rule, by default it will become valid
* and it will set isUpdate() to false
*
* @return void
**/
*/
public function reset() {
$this->_valid = true;
$this->_recordExists = false;
@ -295,8 +299,9 @@ class CakeValidationRule {
/**
* Returns passed options for this rule
*
* @return array
**/
* @param string|int $key Array index
* @return array|null
*/
public function getOptions($key) {
if (!isset($this->_passedOptions[$key])) {
return null;
@ -328,6 +333,8 @@ class CakeValidationRule {
/**
* Parses the rule and sets the rule and ruleParams
*
* @param string $field Field name
* @param array &$data Data array
* @return void
*/
protected function _parseRule($field, &$data) {

View file

@ -4,19 +4,18 @@
*
* Provides the Model validation logic.
*
* PHP versions 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Model.Validator
* @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('CakeValidationRule', 'Model/Validator');
@ -33,7 +32,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
/**
* Holds the CakeValidationRule objects
*
* @var array
* @var CakeValidationRule[]
*/
protected $_rules = array();
@ -41,20 +40,20 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
* List of methods available for validation
*
* @var array
**/
*/
protected $_methods = array();
/**
* I18n domain for validation messages.
*
* @var string
**/
*/
protected $_validationDomain = null;
/**
* Whether the validation is stopped
*
* @var boolean
* @var bool
*/
public $isStopped = false;
@ -75,8 +74,8 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
/**
* Constructor
*
* @param string $fieldName The fieldname
* @param array $ruleset
* @param string $fieldName The fieldname.
* @param array $ruleSet Rules set.
*/
public function __construct($fieldName, $ruleSet) {
$this->field = $fieldName;
@ -94,8 +93,9 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
/**
* Sets the list of methods to use for validation
*
* @param array &$methods Methods list
* @return void
**/
*/
public function setMethods(&$methods) {
$this->_methods =& $methods;
}
@ -114,6 +114,8 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
* Runs all validation rules in this set and returns a list of
* validation errors
*
* @param array $data Data array
* @param bool $isUpdate Is record being updated or created
* @return array list of validation errors for this field
*/
public function validate($data, $isUpdate = false) {
@ -145,10 +147,10 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
}
/**
* Resets interal state for all validation rules in this set
* Resets internal state for all validation rules in this set
*
* @return void
**/
*/
public function reset() {
foreach ($this->getRules() as $rule) {
$rule->reset();
@ -158,7 +160,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
/**
* Gets a rule for a given name if exists
*
* @param string $name
* @param string $name Field name.
* @return CakeValidationRule
*/
public function getRule($name) {
@ -170,7 +172,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
/**
* Returns all rules for this validation set
*
* @return array
* @return CakeValidationRule[]
*/
public function getRules() {
return $this->_rules;
@ -181,15 +183,15 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
*
* ## Example:
*
* {{{
* ```
* $set
* ->setRule('required', array('rule' => 'notEmpty', 'required' => true))
* ->setRule('inRange', array('rule' => array('between', 4, 10))
* }}}
* ->setRule('required', array('rule' => 'notBlank', 'required' => true))
* ->setRule('between', array('rule' => array('lengthBetween', 4, 10))
* ```
*
* @param string $name The name under which the rule should be set
* @param CakeValidationRule|array $rule The validation rule to be set
* @return CakeValidationSet this instance
* @return self
*/
public function setRule($name, $rule) {
if (!($rule instanceof CakeValidationRule)) {
@ -204,14 +206,14 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
*
* ## Example:
*
* {{{
* ```
* $set
* ->removeRule('required')
* ->removeRule('inRange')
* }}}
* ```
*
* @param string $name The name under which the rule should be unset
* @return CakeValidationSet this instance
* @return self
*/
public function removeRule($name) {
unset($this->_rules[$name]);
@ -223,16 +225,16 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
*
* ## Example:
*
* {{{
* ```
* $set->setRules(array(
* 'required' => array('rule' => 'notEmpty', 'required' => true),
* 'required' => array('rule' => 'notBlank', 'required' => true),
* 'inRange' => array('rule' => array('between', 4, 10)
* ));
* }}}
* ```
*
* @param array $rules The rules to be set
* @param bolean $mergeVars [optional] If true, merges vars instead of replace. Defaults to true.
* @return ModelField
* @param bool $mergeVars [optional] If true, merges vars instead of replace. Defaults to true.
* @return self
*/
public function setRules($rules = array(), $mergeVars = true) {
if ($mergeVars === false) {
@ -303,11 +305,11 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
}
/**
* Returns wheter an index exists in the rule set
* Returns whether an index exists in the rule set
*
* @param string $index name of the rule
* @return boolean
**/
* @return bool
*/
public function offsetExists($index) {
return isset($this->_rules[$index]);
}
@ -317,17 +319,22 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
*
* @param string $index name of the rule
* @return CakeValidationRule
**/
*/
public function offsetGet($index) {
return $this->_rules[$index];
}
/**
* Sets or replace a validation rule
* Sets or replace a validation rule.
*
* @param string $index name of the rule
* @param CakeValidationRule|array rule to add to $index
**/
* This is a wrapper for ArrayAccess. Use setRule() directly for
* chainable access.
*
* @param string $index Name of the rule.
* @param CakeValidationRule|array $rule Rule to add to $index.
* @return void
* @see http://www.php.net/manual/en/arrayobject.offsetset.php
*/
public function offsetSet($index, $rule) {
$this->setRule($index, $rule);
}
@ -337,7 +344,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
*
* @param string $index name of the rule
* @return void
**/
*/
public function offsetUnset($index) {
unset($this->_rules[$index]);
}
@ -346,7 +353,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
* Returns an iterator for each of the rules to be applied
*
* @return ArrayIterator
**/
*/
public function getIterator() {
return new ArrayIterator($this->_rules);
}
@ -355,7 +362,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
* Returns the number of rules in this set
*
* @return int
**/
*/
public function count() {
return count($this->_rules);
}