| 1 |
|
<?php |
| 2 |
|
/** |
| 3 |
|
* Xyster Framework |
| 4 |
|
* |
| 5 |
|
* This source file is subject to the new BSD license that is bundled |
| 6 |
|
* with this package in the file LICENSE.txt. |
| 7 |
|
* It is also available through the world-wide-web at this URL: |
| 8 |
|
* http://www.opensource.org/licenses/bsd-license.php |
| 9 |
|
* |
| 10 |
|
* @category Xyster |
| 11 |
|
* @package Xyster_Db |
| 12 |
|
* @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net) |
| 13 |
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| 14 |
|
* @version $Id: Token.php 202 2008-01-20 16:20:09Z doublecompile $ |
| 15 |
|
*/ |
| 16 |
|
/** |
| 17 |
|
* Token containing a SQL fragment and bind values |
| 18 |
|
* |
| 19 |
|
* @category Xyster |
| 20 |
|
* @package Xyster_Db |
| 21 |
|
* @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net) |
| 22 |
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| 23 |
|
*/ |
| 24 |
|
class Xyster_Db_Token |
| 25 |
|
{ |
| 26 |
|
/** |
| 27 |
|
* The SQL fragment |
| 28 |
|
* |
| 29 |
|
* @var string |
| 30 |
|
*/ |
| 31 |
|
protected $_sql; |
| 32 |
|
|
| 33 |
|
/** |
| 34 |
|
* The bind values, if any |
| 35 |
|
* |
| 36 |
|
* @var array |
| 37 |
|
*/ |
| 38 |
|
protected $_bind = array(); |
| 39 |
|
|
| 40 |
|
/** |
| 41 |
|
* Creates a new SqlToken |
| 42 |
|
* |
| 43 |
|
* @param string $sql |
| 44 |
|
* @param array $bind |
| 45 |
|
*/ |
| 46 |
|
public function __construct( $sql, array $bind = array() ) |
| 47 |
|
{ |
| 48 |
82 |
$this->_sql = $sql; |
| 49 |
82 |
$this->_bind = $bind; |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
/** |
| 53 |
|
* Gets the SQL text |
| 54 |
|
* |
| 55 |
|
* @return string |
| 56 |
|
*/ |
| 57 |
|
public function getSql() |
| 58 |
|
{ |
| 59 |
81 |
return $this->_sql; |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
/** |
| 63 |
|
* Gets the bind values for the SQL text (if any) |
| 64 |
|
* |
| 65 |
|
* @return array |
| 66 |
|
*/ |
| 67 |
|
public function getBindValues() |
| 68 |
|
{ |
| 69 |
75 |
return $this->_bind; |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
/** |
| 73 |
|
* Merges the bind values from another token |
| 74 |
|
* |
| 75 |
|
* If keys are the same, values in this token will be overwritten. |
| 76 |
|
* |
| 77 |
|
* @param Xyster_Db_Token $token |
| 78 |
|
*/ |
| 79 |
|
public function addBindValues( Xyster_Db_Token $token ) |
| 80 |
|
{ |
| 81 |
27 |
$this->_bind = array_merge($this->_bind, $token->_bind); |
| 82 |
|
} |
| 83 |
|
} |