Skip to content
Permalink
Browse files

Adding Expression interface to make code inside Expression classes

independent of the query object. Adding file headers
  • Loading branch information...
lorenzo committed Jan 17, 2013
1 parent 1f2d10c commit 743cba4279027ad3049fa1b17a68216fc06462f0
@@ -0,0 +1,24 @@
<?php
/**
*
* PHP Version 5.4
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2013, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Datasource.Database
* @since CakePHP(tm) v 3.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Model\Datasource\Database;
interface Expression {

This comment has been minimized.

Copy link
@markstory

markstory Jan 28, 2013

Member

Most of the other interfaces have the Interface suffix. Should we try to keep that convention consistent here?

This comment has been minimized.

Copy link
@lorenzo

lorenzo Jan 28, 2013

Author Member

that would make me slightly sad, but yes... that is the convention we agreed upon

public function sql();
}
@@ -1,7 +1,24 @@
<?php
/**
*
* PHP Version 5.4
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Datasource.Database
* @since CakePHP(tm) v 3.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Model\Datasource\Database\Expression;
use Cake\Model\Datasource\Database\Expression;
class Comparisson extends QueryExpression {
protected $_field;
@@ -33,7 +50,7 @@ public function getValue() {
public function sql() {
$value = $this->_value;
$template = '%s %s (%s)';
if (is_scalar($this->_value)) {
if (!($this->_value instanceof Expression)) {
$value = $this->_bindValue($this->_field,$value, $this->_type);
$template = '%s %s %s';
}
@@ -1,11 +1,27 @@
<?php
/**
*
* PHP Version 5.4
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2013, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Datasource.Database
* @since CakePHP(tm) v 3.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Model\Datasource\Database\Expression;
use Cake\Model\Datasource\Database\Expression;
use Cake\Model\Datasource\Database\Query;
use \Countable;
class QueryExpression implements Countable {
class QueryExpression implements Expression, Countable {
protected $_conjunction;
@@ -19,7 +35,6 @@ class QueryExpression implements Countable {
protected $_replaceArrayParams = false;
public function __construct($conditions = [], $types = [], $conjunction = 'AND') {
$this->_conjunction = strtoupper($conjunction);
$this->_identifier = substr(spl_object_hash($this), 7, 9);
@@ -242,7 +257,7 @@ protected function _parseCondition($field, $value, $types) {
$template = '%s %s (%s)';
}
if ($value instanceof Query) {
if ($value instanceof Expression) {
return new Comparisson([$expression => $value], [$field => $type], $operator);
}
@@ -1,12 +1,28 @@
<?php
/**
*
* PHP Version 5.4
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2013, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Datasource.Database
* @since CakePHP(tm) v 3.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Model\Datasource\Database;
use Iterator;
use IteratorAggregate;
use Cake\Model\Datasource\Database\Expression\QueryExpression;
use Cake\Model\Datasource\Database\Expression\Comparisson;
class Query implements IteratorAggregate {
class Query implements Expression, IteratorAggregate {
/**
* Connection instance to be used to execute this query
@@ -90,7 +106,7 @@ public function sql() {
if (!count($parts)) {
return;
}
if ($parts instanceof QueryExpression) {
if ($parts instanceof Expression) {
$parts = [$parts->sql()];
}
if (isset($this->_templates[$name])) {
@@ -253,7 +269,7 @@ public function join($tables = null, $types = [], $overwrite = false) {
if (is_string($t)) {
$t = array('table' => $t, 'conditions' => $this->newExpr());
}
if (!($t['conditions']) instanceof QueryExpression) {
if (!($t['conditions']) instanceof Expression) {
$t['conditions'] = $this->newExpr()->add($t['conditions'], $types);
}
$joins[] = $t + ['type' => 'INNER', 'alias' => null];
@@ -1,5 +1,20 @@
<?php
/**
*
* PHP Version 5.4
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2013, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Datasource.Database
* @since CakePHP(tm) v 3.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Model\Datasource\Database\Statement;
class BufferedStatement extends \Cake\Model\Datasource\Database\Statement {
@@ -1,5 +1,20 @@
<?php
/**
*
* PHP Version 5.4
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2013, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Datasource.Database
* @since CakePHP(tm) v 3.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Model\Datasource\Database;
trait TypeConverter {
@@ -9,7 +9,7 @@
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright 2005-2013, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Datasource.Database
* @since CakePHP(tm) v 3.0

0 comments on commit 743cba4

Please sign in to comment.
You can’t perform that action at this time.