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

Commit

Permalink
Merge branch 'hotfix/57'
Browse files Browse the repository at this point in the history
Close #57
  • Loading branch information
weierophinney committed Sep 3, 2015
2 parents f914ccc + e702787 commit 8b29f7f
Show file tree
Hide file tree
Showing 9 changed files with 571 additions and 766 deletions.
31 changes: 13 additions & 18 deletions src/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BaseInputFilter implements
ReplaceableInputInterface
{
/**
* @var null|array|ArrayAccess
* @var null|array
*/
protected $data;

Expand Down Expand Up @@ -106,23 +106,13 @@ public function add($input, $name = null)
/**
* Replace a named input
*
* @param InputInterface|InputFilterInterface $input
* @param mixed $input Any of the input types allowed on add() method.
* @param string $name Name of the input to replace
* @throws Exception\InvalidArgumentException
* @throws Exception\InvalidArgumentException If input to replace not exists.
* @return self
*/
public function replace($input, $name)
{
if (!$input instanceof InputInterface && !$input instanceof InputFilterInterface) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an instance of %s or %s as its first argument; received "%s"',
__METHOD__,
InputInterface::class,
InputFilterInterface::class,
(is_object($input) ? get_class($input) : gettype($input))
));
}

if (!array_key_exists($name, $this->inputs)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s: no input found matching "%s"',
Expand All @@ -131,7 +121,9 @@ public function replace($input, $name)
));
}

$this->inputs[$name] = $input;
$this->remove($name);
$this->add($input, $name);

return $this;
}

Expand Down Expand Up @@ -186,16 +178,16 @@ public function remove($name)
*/
public function setData($data)
{
if (!is_array($data) && !$data instanceof Traversable) {
if ($data instanceof Traversable) {
$data = ArrayUtils::iteratorToArray($data);
}
if (!is_array($data)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an array or Traversable argument; received %s',
__METHOD__,
(is_object($data) ? get_class($data) : gettype($data))
));
}
if (is_object($data) && !$data instanceof ArrayAccess) {
$data = ArrayUtils::iteratorToArray($data);
}
$this->data = $data;
$this->populate();
return $this;
Expand Down Expand Up @@ -433,6 +425,9 @@ public function getRawValue($name)
));
}
$input = $this->inputs[$name];
if ($input instanceof InputFilterInterface) {
return $input->getRawValues();
}
return $input->getRawValue();
}

Expand Down
2 changes: 2 additions & 0 deletions src/CollectionInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public function getCount()
public function setData($data)
{
$this->data = $data;

return $this;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/InputFilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface InputFilterInterface extends Countable
* raise an exception for any they cannot process.
* @param null|string $name Name used to retrieve this input
* @return InputFilterInterface
* @throws Exception\InvalidArgumentInterface if unable to handle the input type.
* @throws Exception\InvalidArgumentException if unable to handle the input type.
*/
public function add($input, $name = null);

Expand Down
10 changes: 8 additions & 2 deletions test/ArrayInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public function testValidationOperatesOnFilteredValue()
$this->input->getFilterChain()->attach($filter);
$validator = new Validator\Digits();
$this->input->getValidatorChain()->attach($validator);
$this->assertTrue($this->input->isValid());
$this->assertTrue(
$this->input->isValid(),
'isValid() value not match. Detail . ' . json_encode($this->input->getMessages())
);
}

public function testSpecifyingMessagesToInputReturnsThoseOnFailedValidation()
Expand Down Expand Up @@ -161,7 +164,10 @@ public function testNotAllowEmptyWithFilterConvertsEmptyToNonEmptyIsValid()
->getFilterChain()->attach(new Filter\Callback(function () {
return 'nonempty';
}));
$this->assertTrue($this->input->isValid());
$this->assertTrue(
$this->input->isValid(),
'isValid() value not match. Detail . ' . json_encode($this->input->getMessages())
);
}

public function testMerge($sourceRawValue = 'bazRawValue')
Expand Down
Loading

0 comments on commit 8b29f7f

Please sign in to comment.