Browse Source

Merge pull request #4056 from dakota/patch-4

3.0 - Fix issue where conditions that are valid global methods get treated as callables
José Lorenzo Rodríguez 11 years ago
parent
commit
f9f4bc2c35

+ 3 - 3
src/Database/Expression/QueryExpression.php

@@ -293,7 +293,7 @@ class QueryExpression implements ExpressionInterface, Countable {
  * @return \Cake\Database\Expression\QueryExpression
  * @return \Cake\Database\Expression\QueryExpression
  */
  */
 	public function and_($conditions, $types = []) {
 	public function and_($conditions, $types = []) {
-		if (is_callable($conditions)) {
+		if (!is_string($conditions) && is_callable($conditions)) {
 			return $conditions(new self([], $this->typeMap()->types($types)));
 			return $conditions(new self([], $this->typeMap()->types($types)));
 		}
 		}
 		return new self($conditions, $this->typeMap()->types($types));
 		return new self($conditions, $this->typeMap()->types($types));
@@ -309,7 +309,7 @@ class QueryExpression implements ExpressionInterface, Countable {
  * @return \Cake\Database\Expression\QueryExpression
  * @return \Cake\Database\Expression\QueryExpression
  */
  */
 	public function or_($conditions, $types = []) {
 	public function or_($conditions, $types = []) {
-		if (is_callable($conditions)) {
+		if (!is_string($conditions) && is_callable($conditions)) {
 			return $conditions(new self([], $this->typeMap()->types($types), 'OR'));
 			return $conditions(new self([], $this->typeMap()->types($types), 'OR'));
 		}
 		}
 		return new self($conditions, $this->typeMap()->types($types), 'OR');
 		return new self($conditions, $this->typeMap()->types($types), 'OR');
@@ -434,7 +434,7 @@ class QueryExpression implements ExpressionInterface, Countable {
 				continue;
 				continue;
 			}
 			}
 
 
-			if (is_callable($c)) {
+			if (!is_string($c) && is_callable($c)) {
 				$expr = new QueryExpression([], $typeMap);
 				$expr = new QueryExpression([], $typeMap);
 				$c = $c($expr, $this);
 				$c = $c($expr, $this);
 			}
 			}

+ 3 - 3
src/Database/Query.php

@@ -245,7 +245,7 @@ class Query implements ExpressionInterface, IteratorAggregate {
  * @return $this
  * @return $this
  */
  */
 	public function select($fields = [], $overwrite = false) {
 	public function select($fields = [], $overwrite = false) {
-		if (is_callable($fields)) {
+		if (!is_string($fields) && is_callable($fields)) {
 			$fields = $fields($this);
 			$fields = $fields($this);
 		}
 		}
 
 
@@ -486,7 +486,7 @@ class Query implements ExpressionInterface, IteratorAggregate {
 				$t = ['table' => $t, 'conditions' => $this->newExpr()];
 				$t = ['table' => $t, 'conditions' => $this->newExpr()];
 			}
 			}
 
 
-			if (is_callable($t['conditions'])) {
+			if (!is_string($t['conditions']) && is_callable($t['conditions'])) {
 				$t['conditions'] = $t['conditions']($this->newExpr(), $this);
 				$t['conditions'] = $t['conditions']($this->newExpr(), $this);
 			}
 			}
 
 
@@ -1557,7 +1557,7 @@ class Query implements ExpressionInterface, IteratorAggregate {
 	protected function _conjugate($part, $append, $conjunction, $types) {
 	protected function _conjugate($part, $append, $conjunction, $types) {
 		$expression = $this->_parts[$part] ?: $this->newExpr();
 		$expression = $this->_parts[$part] ?: $this->newExpr();
 
 
-		if (is_callable($append)) {
+		if (!is_string($append) && is_callable($append)) {
 			$append = $append($this->newExpr(), $this);
 			$append = $append($this->newExpr(), $this);
 		}
 		}
 
 

+ 1 - 1
src/Model/Behavior/CounterCacheBehavior.php

@@ -159,7 +159,7 @@ class CounterCacheBehavior extends Behavior {
 				$config = [];
 				$config = [];
 			}
 			}
 
 
-			if (is_callable($config)) {
+			if (!is_string($config) && is_callable($config)) {
 				$count = $config($event, $entity, $this->_table);
 				$count = $config($event, $entity, $this->_table);
 			} else {
 			} else {
 				$count = $this->_getCount($config, $countConditions);
 				$count = $this->_getCount($config, $countConditions);

+ 1 - 1
src/Validation/ValidationRule.php

@@ -155,7 +155,7 @@ class ValidationRule {
  * @return bool True if the ValidationRule should be skipped
  * @return bool True if the ValidationRule should be skipped
  */
  */
 	protected function _skip($context) {
 	protected function _skip($context) {
-		if (is_callable($this->_on)) {
+		if (!is_string($this->_on) && is_callable($this->_on)) {
 			$function = $this->_on;
 			$function = $this->_on;
 			return !$function($context);
 			return !$function($context);
 		}
 		}