Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documenting and cleaning up, adding missing file
- Loading branch information
Showing
3 changed files
with
204 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* PHP Version 5.4 | ||
* | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.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 (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @since CakePHP(tm) v 3.0.0 | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
namespace Cake\Database; | ||
|
||
class ValueBinder { | ||
|
||
/** | ||
* Array containing a list of bound values to the conditions on this | ||
* object. Each array entry is another array structure containing the actual | ||
* bound value, its type and the placeholder it is bound to. | ||
* | ||
* @var array | ||
*/ | ||
protected $_bindings = []; | ||
|
||
/** | ||
* A counter of the number of parameters bound in this expression object | ||
* | ||
* @var integer | ||
*/ | ||
protected $_bindingsCount = 0; | ||
|
||
/** | ||
* Associates a query placeholder to a value and a type | ||
* | ||
* @param string|integer $token placeholder to be replaced with quoted version | ||
* of $value | ||
* @param mixed $value the value to be bound | ||
* @param string|integer $type the mapped type name, used for casting when sending | ||
* to database | ||
* @return void | ||
*/ | ||
public function bind($param, $value, $type) { | ||
$this->_bindings[$param] = compact('value', 'type') + [ | ||
'placeholder' => is_numeric($param) ? $param : substr($param, 1) | ||
]; | ||
} | ||
|
||
/** | ||
* Creates a unique placeholder name if the token provided does not start with ":" | ||
* otherwise, it will return the same string and internally increment the number | ||
* of placeholders generated by this object. | ||
* | ||
* @param string $token string from which the placeholder will be derived from, | ||
* if it starts with a colon, then the same string is returned | ||
* @return string to be used as a placeholder in a query expression | ||
*/ | ||
public function placeholder($token) { | ||
$param = $token; | ||
$number = $this->_bindingsCount++; | ||
|
||
if ($param[0] !== ':' || $param !== '?') { | ||
$param = sprintf(':c%s', $number); | ||
} | ||
|
||
return $param; | ||
} | ||
|
||
/** | ||
* Returns all values bound to this expression object at this nesting level. | ||
* Subexpression bound values will not be returned with this function. | ||
* | ||
* @return array | ||
*/ | ||
public function bindings() { | ||
return $this->_bindings; | ||
} | ||
|
||
/** | ||
* Clears any bindings taht were previously registered | ||
* | ||
* @return void | ||
*/ | ||
public function reset() { | ||
$this->_bindings = []; | ||
$this->_bindingsCount = 0; | ||
} | ||
|
||
/** | ||
* Resets the bindings count without clearing previously bound values | ||
* | ||
* @return void | ||
*/ | ||
public function resetCount() { | ||
$this->_bindingsCount = 0; | ||
} | ||
|
||
} |