Skip to content

Commit

Permalink
Removing calls to call_user_func in the Database namespace, we can
Browse files Browse the repository at this point in the history
safely expect callables to be passed instead
  • Loading branch information
lorenzo committed Aug 31, 2013
1 parent 1a69d36 commit 519bfc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions lib/Cake/Database/Query.php
Expand Up @@ -282,7 +282,7 @@ public function traverse(callable $visitor) {
protected function _traverseSelect(callable $visitor) {
$parts = ['select', 'from', 'join', 'where', 'group', 'having', 'order', 'limit', 'offset', 'union'];
foreach ($parts as $name) {
call_user_func($visitor, $this->_parts[$name], $name);
$visitor($this->_parts[$name], $name);
}
}

Expand All @@ -295,7 +295,7 @@ protected function _traverseSelect(callable $visitor) {
protected function _traverseDelete(callable $visitor) {
$parts = ['delete', 'from', 'where'];
foreach ($parts as $name) {
call_user_func($visitor, $this->_parts[$name], $name);
$visitor($this->_parts[$name], $name);
}
}

Expand All @@ -308,7 +308,7 @@ protected function _traverseDelete(callable $visitor) {
protected function _traverseUpdate(callable $visitor) {
$parts = ['update', 'set', 'where'];
foreach ($parts as $name) {
call_user_func($visitor, $this->_parts[$name], $name);
$visitor($this->_parts[$name], $name);
}
}

Expand All @@ -321,7 +321,7 @@ protected function _traverseUpdate(callable $visitor) {
protected function _traverseInsert(callable $visitor) {
$parts = ['insert', 'values'];
foreach ($parts as $name) {
call_user_func($visitor, $this->_parts[$name], $name);
$visitor($this->_parts[$name], $name);
}
}

Expand Down Expand Up @@ -352,7 +352,7 @@ protected function _traverseInsert(callable $visitor) {
*/
public function select($fields = [], $overwrite = false) {
if (is_callable($fields)) {
$fields = call_user_func($fields, $this);
$fields = $fields($this);
}

if (!is_array($fields)) {
Expand Down Expand Up @@ -1457,7 +1457,7 @@ public function traverseExpressions(callable $callback) {
$visitor = function($expression) use (&$visitor, $callback) {
if (is_array($expression)) {
foreach ($expression as $e) {
call_user_func($visitor, $e);
$visitor($e);
}
return;
}
Expand All @@ -1466,7 +1466,7 @@ public function traverseExpressions(callable $callback) {
$expression->traverse($visitor);

if (!($expression instanceof self)) {
call_user_func($callback, $expression);
$callback($expression);
}
}
};
Expand Down Expand Up @@ -1568,7 +1568,7 @@ protected function _conjugate($part, $append, $conjunction, $types) {
$expression = $this->_parts[$part] ?: $this->newExpr();

if (is_callable($append)) {
$append = call_user_func($append, $this->newExpr(), $this);
$append = $append($this->newExpr(), $this);
}

if ($expression->type() === $conjunction) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Database/Type.php
Expand Up @@ -56,7 +56,7 @@ class Type {
'uuid' => ['callback' => 'strval'],
'text' => ['callback' => 'strval'],
'boolean' => [
'callback' => '\Cake\Database\Type::boolval',
'callback' => ['\Cake\Database\Type', 'boolval'],
'pdo' => PDO::PARAM_BOOL
],
];
Expand Down Expand Up @@ -186,7 +186,7 @@ protected function _basicTypeCast($value, Driver $driver) {
if (!empty(self::$_basicTypes[$this->_name])) {
$typeInfo = self::$_basicTypes[$this->_name];
if (isset($typeInfo['callback'])) {
return call_user_func($typeInfo['callback'], $value);
return $typeInfo['callback']($value);
}
}
return $value;
Expand Down

0 comments on commit 519bfc5

Please sign in to comment.