Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Hotfix/db parametercontainer mixed use #3692

Closed
wants to merge 2 commits into from

2 participants

@ralphschindler
Collaborator

Fixed ParameterContainer to do lookups when index provided offsets are provided, and when named parameters are already supplied.

ralphschindler added some commits
@ralphschindler ralphschindler Zend\Db\Adapter\ParameterContainer
- Fixed ParameterContainer to, upon offsetSet, map int-indexed parameter to named-parameter
39d0104
@ralphschindler ralphschindler Zend\Db\Adapter\ParameterContainer
- Added more tests and a situation for null insertion
430cee4
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3692' into develop
Forward port #3692
d4b577d
@weierophinney weierophinney was assigned
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3692'
Close #3692
e7b4121
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3692' into develop
Forward port #3692
f2a8b2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 6, 2013
  1. @ralphschindler

    Zend\Db\Adapter\ParameterContainer

    ralphschindler authored
    - Fixed ParameterContainer to, upon offsetSet, map int-indexed parameter to named-parameter
  2. @ralphschindler

    Zend\Db\Adapter\ParameterContainer

    ralphschindler authored
    - Added more tests and a situation for null insertion
This page is out of date. Refresh to see the latest.
View
29 library/Zend/Db/Adapter/ParameterContainer.php
@@ -91,10 +91,31 @@ public function offsetSetReference($name, $from)
*/
public function offsetSet($name, $value, $errata = null)
{
- $this->data[$name] = $value;
+ $position = false;
- $names = array_keys($this->data);
- $this->positions[array_search($name, $names)] = $name;
+ // if integer, get name for this position
+ if (is_int($name)) {
+ if (isset($this->positions[$name])) {
+ $position = $name;
+ $name = $this->positions[$name];
+ } else {
+ $name = (string) $name;
+ }
+ } elseif (is_string($name)) {
+ // is a string:
+ $currentNames = array_keys($this->data);
+ $position = array_search($name, $currentNames, true);
+ } elseif ($name === null) {
+ $name = (string) count($this->data);
+ } else {
+ throw new Exception\InvalidArgumentException('Keys must be string, integer or null');
+ }
+
+ if ($position === false) {
+ $this->positions[] = $name;
+ }
+
+ $this->data[$name] = $value;
if ($errata) {
$this->offsetSetErrata($name, $errata);
@@ -109,7 +130,7 @@ public function offsetSet($name, $value, $errata = null)
*/
public function offsetUnset($name)
{
- if (is_int($name)) {
+ if (is_int($name) && isset($this->positions[$name])) {
$name = $this->positions[$name];
}
unset($this->data[$name]);
View
25 tests/ZendTest/Db/Adapter/ParameterContainerTest.php
@@ -72,6 +72,31 @@ public function testOffsetSet()
);
$this->assertEquals('string', $this->parameterContainer->offsetGetErrata('1'));
+
+ // test that setting an index applies to correct named parameter
+ $this->parameterContainer[0] = 'Zero';
+ $this->parameterContainer[1] = 'One';
+ $this->assertEquals(
+ array('foo' => 'Zero', 'boo' => 'One', '1' => 'book'),
+ $this->parameterContainer->getNamedArray()
+ );
+ $this->assertEquals(
+ array(0 => 'Zero', 1 => 'One', 2 => 'book'),
+ $this->parameterContainer->getPositionalArray()
+ );
+
+ // test no-index applies
+ $this->parameterContainer['buffer'] = 'A buffer Element';
+ $this->parameterContainer[] = 'Second To Last';
+ $this->parameterContainer[] = 'Last';
+ $this->assertEquals(
+ array('foo' => 'Zero', 'boo' => 'One', '1' => 'book', 'buffer' => 'A buffer Element', '4' => 'Second To Last', '5' => 'Last'),
+ $this->parameterContainer->getNamedArray()
+ );
+ $this->assertEquals(
+ array(0 => 'Zero', 1 => 'One', 2 => 'book', 3 => 'A buffer Element', 4 => 'Second To Last', 5 => 'Last'),
+ $this->parameterContainer->getPositionalArray()
+ );
}
/**
Something went wrong with that request. Please try again.