Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions library/Zend/Db/Sql/Predicate/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class In implements PredicateInterface
/**
* Constructor
*
* @param null|string $identifier
* @param array $valueSet
* @param null|string|array $identifier
* @param null|array|Select $valueSet
*/
public function __construct($identifier = null, $valueSet = null)
{
Expand All @@ -39,19 +39,20 @@ public function __construct($identifier = null, $valueSet = null)
/**
* Set identifier for comparison
*
* @param string $identifier
* @param string|array $identifier
* @return In
*/
public function setIdentifier($identifier)
{
$this->identifier = $identifier;

return $this;
}

/**
* Get identifier of comparison
*
* @return null|string
* @return null|string|array
*/
public function getIdentifier()
{
Expand All @@ -61,7 +62,7 @@ public function getIdentifier()
/**
* Set set of values for IN comparison
*
* @param array $valueSet
* @param array|Select $valueSet
* @throws Exception\InvalidArgumentException
* @return In
*/
Expand All @@ -73,9 +74,15 @@ public function setValueSet($valueSet)
);
}
$this->valueSet = $valueSet;

return $this;
}

/**
* Gets set of values in IN comparision
*
* @return array|Select
*/
public function getValueSet()
{
return $this->valueSet;
Expand All @@ -89,7 +96,21 @@ public function getValueSet()
public function getExpressionData()
{
$values = $this->getValueSet();
$identifier = $this->getIdentifier();
if ($values instanceof Select) {
if (is_array($identifier)) {
$identifiers = $identifier;
$specification = ' ( ' . implode(', ', array_fill(0, count($identifiers), '%s')) . ' ) ';
$specification .= ' IN %s';
$types = array_fill(0, count($identifiers), self::TYPE_IDENTIFIER);
$types[] = self::TYPE_VALUE;

return array(array(
$specification,
array_merge($identifiers, array($values)),
$types,
));
}
$specification = $this->selectSpecification;
$types = array(self::TYPE_VALUE);
$values = array($values);
Expand All @@ -98,7 +119,6 @@ public function getExpressionData()
$types = array_fill(0, count($values), self::TYPE_VALUE);
}

$identifier = $this->getIdentifier();
array_unshift($values, $identifier);
array_unshift($types, self::TYPE_IDENTIFIER);

Expand Down
11 changes: 11 additions & 0 deletions tests/ZendTest/Db/Sql/Predicate/InTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,15 @@ public function testGetExpressionDataWithSubselect()
));
$this->assertEquals($expected, $in->getExpressionData());
}

public function testGetExpressionDataWithSubselectAndArrayIdentifier()
{
$in = new In(array('foo', 'bar'), $select = new Select);
$expected = array(array(
' ( %s, %s ) IN %s',
array('foo', 'bar', $select),
array($in::TYPE_IDENTIFIER, $in::TYPE_IDENTIFIER, $in::TYPE_VALUE)
));
$this->assertEquals($expected, $in->getExpressionData());
}
}