Skip to content

Commit

Permalink
Renaming FieldExpression to IdentifierExpression everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Nov 7, 2013
1 parent 4b3feb0 commit 3c049f9
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 60 deletions.
30 changes: 15 additions & 15 deletions Cake/Database/Expression/IdentifierExpression.php
Expand Up @@ -20,45 +20,45 @@
use Cake\Database\ValueBinder;

/**
* Represents a single field name in the database
* Represents a single identifier name in the database
*
*/
class FieldExpression implements ExpressionInterface {
class IdentifierExpression implements ExpressionInterface {

/**
* Holds the field string
* Holds the identifier string
*
* @var string
*/
protected $_field;
protected $_identifier;

/**
* Constructor
*
* @param string $field The field this expression represents
* @param string $identifier The identifier this expression represents
* @return void
*/
public function __construct($field) {
$this->setField($field);
public function __construct($identifier) {
$this->setIdentifier($identifier);
}

/**
* Sets the field this expression represents
* Sets the identifier this expression represents
*
* @param string $field
* @param string $identifier
* @return void
*/
public function setField($field) {
$this->_field = $field;
public function setIdentifier($identifier) {
$this->_identifier = $identifier;
}

/**
* Returns the field this expression represents
* Returns the identifier this expression represents
*
* @return string
*/
public function getField() {
return $this->_field;
public function getIdentifier() {
return $this->_identifier;
}

/**
Expand All @@ -68,7 +68,7 @@ public function getField() {
* @return string
*/
public function sql(ValueBinder $generator) {
return $this->_field;
return $this->_identifier;
}

/**
Expand Down
12 changes: 7 additions & 5 deletions Cake/Database/SqlDialectTrait.php
Expand Up @@ -18,7 +18,7 @@

use Cake\Database\Expression\Comparison;
use Cake\Database\Expression\OrderByExpression;
use Cake\Database\Expression\FieldExpression;
use Cake\Database\Expression\IdentifierExpression;

trait SqlDialectTrait {

Expand Down Expand Up @@ -113,7 +113,7 @@ protected function _expressionTranslators() {
return [
$namespace . '\Comparison' => '_quoteComparison',
$namespace . '\OrderByExpression' => '_quoteOrderBy',
$namespace . '\FieldExpression' => '_quoteField'
$namespace . '\IdentifierExpression' => '_quoteField'
];
}

Expand Down Expand Up @@ -151,11 +151,13 @@ protected function _quoteOrderBy(OrderByExpression $expression) {
/**
* Quotes identifiers in "order by" expression objects
*
* @param \Cake\Database\Expression\FieldExpression $expression
* @param \Cake\Database\Expression\IdentifierExpression $expression
* @return void
*/
protected function _quoteField(FieldExpression $expression) {
$expression->setField($this->quoteIdentifier($expression->getField()));
protected function _quoteField(IdentifierExpression $expression) {
$expression->setIdentifier(
$this->quoteIdentifier($expression->getIdentifier())
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Cake/ORM/Association/BelongsTo.php
Expand Up @@ -16,7 +16,7 @@
*/
namespace Cake\ORM\Association;

use Cake\Database\Expression\FieldExpression;
use Cake\Database\Expression\IdentifierExpression;
use Cake\ORM\Association;
use Cake\ORM\Entity;
use Cake\ORM\Query;
Expand Down Expand Up @@ -80,7 +80,7 @@ protected function _joinCondition(array $options) {
$this->target()->alias(),
$this->_targetTable->primaryKey()
);
$value = new FieldExpression(sprintf(
$value = new IdentifierExpression(sprintf(
'%s.%s',
$this->_sourceTable->alias(),
$options['foreignKey']
Expand Down
4 changes: 2 additions & 2 deletions Cake/ORM/Association/ExternalAssociationTrait.php
Expand Up @@ -16,7 +16,7 @@
*/
namespace Cake\ORM\Association;

use Cake\Database\Expression\FieldExpression;
use Cake\Database\Expression\IdentifierExpression;
use Cake\ORM\Query;
use Cake\Utility\Inflector;

Expand Down Expand Up @@ -127,7 +127,7 @@ protected function _joinCondition(array $options) {
$this->_sourceTable->alias(),
$this->_sourceTable->primaryKey()
);
$value = new FieldExpression(sprintf(
$value = new IdentifierExpression(sprintf(
'%s.%s',
$this->_targetTable->alias(),
$options['foreignKey']
Expand Down
4 changes: 2 additions & 2 deletions Cake/ORM/Association/HasOne.php
Expand Up @@ -16,7 +16,7 @@
*/
namespace Cake\ORM\Association;

use Cake\Database\Expression\FieldExpression;
use Cake\Database\Expression\IdentifierExpression;
use Cake\ORM\Association;
use Cake\ORM\Association\DependentDeleteTrait;
use Cake\ORM\Query;
Expand Down Expand Up @@ -75,7 +75,7 @@ protected function _joinCondition(array $options) {
$this->_sourceTable->alias(),
$this->_sourceTable->primaryKey()
);
$value = new FieldExpression(sprintf(
$value = new IdentifierExpression(sprintf(
'%s.%s', $this->_targetTable->alias(), $options['foreignKey']
));
return [$field => $value];
Expand Down
Expand Up @@ -16,26 +16,26 @@
*/
namespace Cake\Test\TestCase\Database\Expression;

use Cake\Database\Expression\FieldExpression;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Database\ValueBinder;
use Cake\TestSuite\TestCase;

/**
* Tests FieldExpression class
* Tests IdentifierExpression class
*
**/
class FieldExpressionTest extends TestCase {
class IdentifierExpressionTest extends TestCase {

/**
* Tests getting and setting the field
*
* @return
* @return
*/
public function testGetAndSet() {
$expression = new FieldExpression('foo');
$this->assertEquals('foo', $expression->getField());
$expression->setField('bar');
$this->assertEquals('bar', $expression->getField());
$expression = new IdentifierExpression('foo');
$this->assertEquals('foo', $expression->getIdentifier());
$expression->setIdentifier('bar');
$this->assertEquals('bar', $expression->getIdentifier());
}

/**
Expand All @@ -44,7 +44,7 @@ public function testGetAndSet() {
* @return void
*/
public function testSQL() {
$expression = new FieldExpression('foo');
$expression = new IdentifierExpression('foo');
$this->assertEquals('foo', $expression->sql(new ValueBinder));
}

Expand Down
6 changes: 3 additions & 3 deletions Cake/Test/TestCase/Database/QueryTest.php
Expand Up @@ -18,7 +18,7 @@

use Cake\Core\Configure;
use Cake\Database\ConnectionManager;
use Cake\Database\Expression\FieldExpression;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Database\Query;
use Cake\TestSuite\TestCase;

Expand Down Expand Up @@ -2054,7 +2054,7 @@ public function testQuotingSelectFieldsAndAlias() {
$this->assertRegExp('/SELECT \(1 \+ 1\) AS [`"]foo[`"]$/', $sql);

$query = new Query($this->connection);
$sql = $query->select(['foo' => new FieldExpression('bar')])->sql();
$sql = $query->select(['foo' => new IdentifierExpression('bar')])->sql();
$this->assertRegExp('/[`"]bar[`"]/', $sql);
}

Expand Down Expand Up @@ -2126,7 +2126,7 @@ public function testQuotingGroupBy() {
$this->assertRegExp('/GROUP BY \(bar\)/', $sql);

$query = new Query($this->connection);
$sql = $query->select('*')->group([new FieldExpression('bar')])->sql();
$sql = $query->select('*')->group([new IdentifierExpression('bar')])->sql();
$this->assertRegExp('/GROUP BY \([`"]bar[`"]\)/', $sql);
}

Expand Down
10 changes: 5 additions & 5 deletions Cake/Test/TestCase/ORM/Association/BelongsToManyTest.php
Expand Up @@ -16,7 +16,7 @@
*/
namespace Cake\Test\TestCase\ORM\Association;

use Cake\Database\Expression\FieldExpression;
use Cake\Database\Expression\IdentifierExpression;
use Cake\ORM\Association\BelongsToMany;
use Cake\ORM\Entity;
use Cake\ORM\Query;
Expand Down Expand Up @@ -185,8 +185,8 @@ public function testAttachTo() {
]
]);

$field1 = new FieldExpression('ArticlesTag.article_id');
$field2 = new FieldExpression('ArticlesTag.tag_id');
$field1 = new IdentifierExpression('ArticlesTag.article_id');
$field2 = new IdentifierExpression('ArticlesTag.tag_id');

$query->expects($this->at(2))->method('join')->with([
'ArticlesTag' => [
Expand Down Expand Up @@ -239,8 +239,8 @@ public function testAttachToNoFields() {
]
]);

$field1 = new FieldExpression('ArticlesTag.article_id');
$field2 = new FieldExpression('ArticlesTag.tag_id');
$field1 = new IdentifierExpression('ArticlesTag.article_id');
$field2 = new IdentifierExpression('ArticlesTag.tag_id');

$query->expects($this->at(1))->method('join')->with([
'ArticlesTag' => [
Expand Down
6 changes: 3 additions & 3 deletions Cake/Test/TestCase/ORM/Association/BelongsToTest.php
Expand Up @@ -16,7 +16,7 @@
*/
namespace Cake\Test\TestCase\ORM\Association;

use Cake\Database\Expression\FieldExpression;
use Cake\Database\Expression\IdentifierExpression;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Entity;
use Cake\ORM\Query;
Expand Down Expand Up @@ -86,7 +86,7 @@ public function testAttachTo() {
'conditions' => ['Company.is_active' => true]
];
$association = new BelongsTo('Company', $config);
$field = new FieldExpression('Client.company_id');
$field = new IdentifierExpression('Client.company_id');
$query->expects($this->once())->method('join')->with([
'Company' => [
'conditions' => [
Expand Down Expand Up @@ -151,7 +151,7 @@ public function testAttachToNoFields() {
'conditions' => ['Company.is_active' => true]
];
$association = new BelongsTo('Company', $config);
$field = new FieldExpression('Client.company_id');
$field = new IdentifierExpression('Client.company_id');
$query->expects($this->once())->method('join')->with([
'Company' => [
'conditions' => [
Expand Down
6 changes: 3 additions & 3 deletions Cake/Test/TestCase/ORM/Association/HasManyTest.php
Expand Up @@ -16,7 +16,7 @@
*/
namespace Cake\Test\TestCase\ORM\Association;

use Cake\Database\Expression\FieldExpression;
use Cake\Database\Expression\IdentifierExpression;
use Cake\ORM\Association\HasMany;
use Cake\ORM\Entity;
use Cake\ORM\Query;
Expand Down Expand Up @@ -355,7 +355,7 @@ public function testAttachTo() {
'conditions' => ['Article.is_active' => true]
];

$field = new FieldExpression('Article.author_id');
$field = new IdentifierExpression('Article.author_id');
$association = new HasMany('Article', $config);
$query->expects($this->once())->method('join')->with([
'Article' => [
Expand Down Expand Up @@ -421,7 +421,7 @@ public function testAttachToNoFields() {
'targetTable' => $this->article,
'conditions' => ['Article.is_active' => true]
];
$field = new FieldExpression('Article.author_id');
$field = new IdentifierExpression('Article.author_id');
$association = new HasMany('Article', $config);
$query->expects($this->once())->method('join')->with([
'Article' => [
Expand Down
6 changes: 3 additions & 3 deletions Cake/Test/TestCase/ORM/Association/HasOneTest.php
Expand Up @@ -16,7 +16,7 @@
*/
namespace Cake\Test\TestCase\ORM\Association;

use Cake\Database\Expression\FieldExpression;
use Cake\Database\Expression\IdentifierExpression;
use Cake\ORM\Association\HasOne;
use Cake\ORM\Query;
use Cake\ORM\Table;
Expand Down Expand Up @@ -85,7 +85,7 @@ public function testAttachTo() {
'conditions' => ['Profile.is_active' => true]
];
$association = new HasOne('Profile', $config);
$field = new FieldExpression('Profile.user_id');
$field = new IdentifierExpression('Profile.user_id');
$query->expects($this->once())->method('join')->with([
'Profile' => [
'conditions' => [
Expand Down Expand Up @@ -152,7 +152,7 @@ public function testAttachToNoFields() {
'conditions' => ['Profile.is_active' => true]
];
$association = new HasOne('Profile', $config);
$field = new FieldExpression('Profile.user_id');
$field = new IdentifierExpression('Profile.user_id');
$query->expects($this->once())->method('join')->with([
'Profile' => [
'conditions' => [
Expand Down

0 comments on commit 3c049f9

Please sign in to comment.