Added 'contains' comparison
This commit is contained in:
parent
399584db4c
commit
760623346c
@ -15,6 +15,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.2",
|
"php": ">=5.3.2",
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
|
"doctrine/collections": "~1.1",
|
||||||
"doctrine/dbal": ">=2.4-dev,<2.5-dev",
|
"doctrine/dbal": ">=2.4-dev,<2.5-dev",
|
||||||
"symfony/console": "2.*"
|
"symfony/console": "2.*"
|
||||||
},
|
},
|
||||||
|
58
composer.lock
generated
58
composer.lock
generated
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"hash": "eff8840dfb1a83e6e1aef32b8031ac7c",
|
"hash": "acae8c9f654bd03696631d5eac8d16ad",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "doctrine/annotations",
|
"name": "doctrine/annotations",
|
||||||
@ -22,7 +22,6 @@
|
|||||||
"require-dev": {
|
"require-dev": {
|
||||||
"doctrine/cache": "1.*"
|
"doctrine/cache": "1.*"
|
||||||
},
|
},
|
||||||
"time": "2013-01-12 19:23:32",
|
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
@ -65,7 +64,8 @@
|
|||||||
"annotations",
|
"annotations",
|
||||||
"docblock",
|
"docblock",
|
||||||
"parser"
|
"parser"
|
||||||
]
|
],
|
||||||
|
"time": "2013-01-12 19:23:32"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "doctrine/cache",
|
"name": "doctrine/cache",
|
||||||
@ -84,7 +84,6 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.2"
|
"php": ">=5.3.2"
|
||||||
},
|
},
|
||||||
"time": "2013-01-10 22:43:46",
|
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
@ -126,27 +125,32 @@
|
|||||||
"keywords": [
|
"keywords": [
|
||||||
"cache",
|
"cache",
|
||||||
"caching"
|
"caching"
|
||||||
]
|
],
|
||||||
|
"time": "2013-01-10 22:43:46"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "doctrine/collections",
|
"name": "doctrine/collections",
|
||||||
"version": "v1.0",
|
"version": "dev-master",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/doctrine/collections.git",
|
"url": "https://github.com/doctrine/collections.git",
|
||||||
"reference": "v1.0"
|
"reference": "560f29c39cfcfbcd210e5d549d993a39d898b04b"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://github.com/doctrine/collections/archive/v1.0.zip",
|
"url": "https://api.github.com/repos/doctrine/collections/zipball/560f29c39cfcfbcd210e5d549d993a39d898b04b",
|
||||||
"reference": "v1.0",
|
"reference": "560f29c39cfcfbcd210e5d549d993a39d898b04b",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.2"
|
"php": ">=5.3.2"
|
||||||
},
|
},
|
||||||
"time": "2013-01-12 16:36:50",
|
|
||||||
"type": "library",
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.1.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
"Doctrine\\Common\\Collections\\": "lib/"
|
"Doctrine\\Common\\Collections\\": "lib/"
|
||||||
@ -188,7 +192,8 @@
|
|||||||
"array",
|
"array",
|
||||||
"collections",
|
"collections",
|
||||||
"iterator"
|
"iterator"
|
||||||
]
|
],
|
||||||
|
"time": "2013-03-07 12:15:54"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "doctrine/common",
|
"name": "doctrine/common",
|
||||||
@ -212,7 +217,6 @@
|
|||||||
"doctrine/lexer": "1.*",
|
"doctrine/lexer": "1.*",
|
||||||
"php": ">=5.3.2"
|
"php": ">=5.3.2"
|
||||||
},
|
},
|
||||||
"time": "2013-01-29 12:48:56",
|
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
@ -262,7 +266,8 @@
|
|||||||
"eventmanager",
|
"eventmanager",
|
||||||
"persistence",
|
"persistence",
|
||||||
"spl"
|
"spl"
|
||||||
]
|
],
|
||||||
|
"time": "2013-01-29 12:48:56"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "doctrine/dbal",
|
"name": "doctrine/dbal",
|
||||||
@ -288,7 +293,6 @@
|
|||||||
"suggest": {
|
"suggest": {
|
||||||
"symfony/console": "For helpful console commands such as SQL execution and import of files."
|
"symfony/console": "For helpful console commands such as SQL execution and import of files."
|
||||||
},
|
},
|
||||||
"time": "2013-02-09 23:28:29",
|
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
@ -331,7 +335,8 @@
|
|||||||
"dbal",
|
"dbal",
|
||||||
"persistence",
|
"persistence",
|
||||||
"queryobject"
|
"queryobject"
|
||||||
]
|
],
|
||||||
|
"time": "2013-02-09 23:28:29"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "doctrine/inflector",
|
"name": "doctrine/inflector",
|
||||||
@ -350,7 +355,6 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.2"
|
"php": ">=5.3.2"
|
||||||
},
|
},
|
||||||
"time": "2013-01-10 21:49:15",
|
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
@ -394,7 +398,8 @@
|
|||||||
"pluarlize",
|
"pluarlize",
|
||||||
"singuarlize",
|
"singuarlize",
|
||||||
"string"
|
"string"
|
||||||
]
|
],
|
||||||
|
"time": "2013-01-10 21:49:15"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "doctrine/lexer",
|
"name": "doctrine/lexer",
|
||||||
@ -413,7 +418,6 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.2"
|
"php": ">=5.3.2"
|
||||||
},
|
},
|
||||||
"time": "2013-01-12 18:59:04",
|
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
@ -446,7 +450,8 @@
|
|||||||
"keywords": [
|
"keywords": [
|
||||||
"lexer",
|
"lexer",
|
||||||
"parser"
|
"parser"
|
||||||
]
|
],
|
||||||
|
"time": "2013-01-12 18:59:04"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/console",
|
"name": "symfony/console",
|
||||||
@ -466,7 +471,6 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.3"
|
"php": ">=5.3.3"
|
||||||
},
|
},
|
||||||
"time": "2013-01-31 21:39:01",
|
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
@ -493,15 +497,25 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Symfony Console Component",
|
"description": "Symfony Console Component",
|
||||||
"homepage": "http://symfony.com"
|
"homepage": "http://symfony.com",
|
||||||
|
"time": "2013-01-31 21:39:01"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": null,
|
"packages-dev": [
|
||||||
|
|
||||||
|
],
|
||||||
"aliases": [
|
"aliases": [
|
||||||
|
|
||||||
],
|
],
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"stability-flags": [
|
"stability-flags": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"platform": {
|
||||||
|
"php": ">=5.3.2",
|
||||||
|
"ext-pdo": "*"
|
||||||
|
},
|
||||||
|
"platform-dev": [
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -84,15 +84,16 @@ class BasicEntityPersister
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
static private $comparisonMap = array(
|
static private $comparisonMap = array(
|
||||||
Comparison::EQ => '= %s',
|
Comparison::EQ => '= %s',
|
||||||
Comparison::IS => 'IS %s',
|
Comparison::IS => 'IS %s',
|
||||||
Comparison::NEQ => '!= %s',
|
Comparison::NEQ => '!= %s',
|
||||||
Comparison::GT => '> %s',
|
Comparison::GT => '> %s',
|
||||||
Comparison::GTE => '>= %s',
|
Comparison::GTE => '>= %s',
|
||||||
Comparison::LT => '< %s',
|
Comparison::LT => '< %s',
|
||||||
Comparison::LTE => '<= %s',
|
Comparison::LTE => '<= %s',
|
||||||
Comparison::IN => 'IN (%s)',
|
Comparison::IN => 'IN (%s)',
|
||||||
Comparison::NIN => 'NOT IN (%s)',
|
Comparison::NIN => 'NOT IN (%s)',
|
||||||
|
Comparison::CONTAINS => 'LIKE %s',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +50,7 @@ class SqlValueVisitor extends ExpressionVisitor
|
|||||||
*/
|
*/
|
||||||
public function walkComparison(Comparison $comparison)
|
public function walkComparison(Comparison $comparison)
|
||||||
{
|
{
|
||||||
$value = $comparison->getValue()->getValue();
|
$value = $this->getValueFromComparison($comparison);
|
||||||
$field = $comparison->getField();
|
$field = $comparison->getField();
|
||||||
|
|
||||||
$this->values[] = $value;
|
$this->values[] = $value;
|
||||||
@ -92,4 +92,20 @@ class SqlValueVisitor extends ExpressionVisitor
|
|||||||
{
|
{
|
||||||
return array($this->values, $this->types);
|
return array($this->values, $this->types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value from a Comparison. In case of a CONTAINS comparison,
|
||||||
|
* the value is wrapped in %-signs, because it will be used in a LIKE clause.
|
||||||
|
*
|
||||||
|
* @param \Doctrine\Common\Collections\Expr\Comparison $comparison
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getValueFromComparison(Comparison $comparison)
|
||||||
|
{
|
||||||
|
$value = $comparison->getValue()->getValue();
|
||||||
|
|
||||||
|
return $comparison->getOperator() == Comparison::CONTAINS
|
||||||
|
? "%{$value}%"
|
||||||
|
: $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -781,6 +781,22 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertEquals(4, count($users));
|
$this->assertEquals(4, count($users));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMatchingCriteriaContainsComparison()
|
||||||
|
{
|
||||||
|
$this->loadFixture();
|
||||||
|
|
||||||
|
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
|
||||||
|
|
||||||
|
$users = $repository->matching(new Criteria(Criteria::expr()->contains('name', 'Foobar')));
|
||||||
|
$this->assertEquals(0, count($users));
|
||||||
|
|
||||||
|
$users = $repository->matching(new Criteria(Criteria::expr()->contains('name', 'Rom')));
|
||||||
|
$this->assertEquals(1, count($users));
|
||||||
|
|
||||||
|
$users = $repository->matching(new Criteria(Criteria::expr()->contains('status', 'dev')));
|
||||||
|
$this->assertEquals(2, count($users));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group DDC-2055
|
* @group DDC-2055
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user