Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Commit

Permalink
Fixing the setting of collectionRawValues on CollectionInputFilters. …
Browse files Browse the repository at this point in the history
…In the past these may have contained incorrect data, causing collections to not be re-populated or validated correctly.
  • Loading branch information
rkeet committed Jul 6, 2018
1 parent 198cd95 commit 8974de7
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/InputFilter/CollectionInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,50 @@ public function isValid($context = null)
}

$this->collectionValues[$key] = $inputFilter->getValues();
$this->collectionRawValues[$key] = $inputFilter->getRawValues();

// https://github.com/zendframework/zend-inputfilter/pull/169
// $this->collectionRawValues[$key] = $inputFilter->getRawValues();
}

return $valid;
}

/**
* {@inheritdoc}
*
* Sets the collectionRawValues without any modifications.
*/
public function setData($data)
{
if ( ! (is_array($data) || $data instanceof Traversable)) {
throw new InvalidArgumentException(
sprintf(
'%s expects an array or Traversable collection; invalid collection of type %s provided',
__METHOD__,
is_object($data) ? get_class($data) : gettype($data)
)
);
}

// https://github.com/zendframework/zend-inputfilter/pull/169
$this->collectionRawValues = $data;

foreach ($data as $item) {
if (is_array($item) || $item instanceof Traversable) {
continue;
}

throw new InvalidArgumentException(
sprintf(
'%s expects each item in a collection to be an array or Traversable; '
. 'invalid item in collection of type %s detected',
__METHOD__,
is_object($item) ? get_class($item) : gettype($item)
)
);
}

$this->data = $data;
return $this;
}
}

0 comments on commit 8974de7

Please sign in to comment.