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

Commit 8b29f7f

Browse files
committed
Merge branch 'hotfix/57'
Close #57
2 parents f914ccc + e702787 commit 8b29f7f

9 files changed

+571
-766
lines changed

src/BaseInputFilter.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class BaseInputFilter implements
2121
ReplaceableInputInterface
2222
{
2323
/**
24-
* @var null|array|ArrayAccess
24+
* @var null|array
2525
*/
2626
protected $data;
2727

@@ -106,23 +106,13 @@ public function add($input, $name = null)
106106
/**
107107
* Replace a named input
108108
*
109-
* @param InputInterface|InputFilterInterface $input
109+
* @param mixed $input Any of the input types allowed on add() method.
110110
* @param string $name Name of the input to replace
111-
* @throws Exception\InvalidArgumentException
111+
* @throws Exception\InvalidArgumentException If input to replace not exists.
112112
* @return self
113113
*/
114114
public function replace($input, $name)
115115
{
116-
if (!$input instanceof InputInterface && !$input instanceof InputFilterInterface) {
117-
throw new Exception\InvalidArgumentException(sprintf(
118-
'%s expects an instance of %s or %s as its first argument; received "%s"',
119-
__METHOD__,
120-
InputInterface::class,
121-
InputFilterInterface::class,
122-
(is_object($input) ? get_class($input) : gettype($input))
123-
));
124-
}
125-
126116
if (!array_key_exists($name, $this->inputs)) {
127117
throw new Exception\InvalidArgumentException(sprintf(
128118
'%s: no input found matching "%s"',
@@ -131,7 +121,9 @@ public function replace($input, $name)
131121
));
132122
}
133123

134-
$this->inputs[$name] = $input;
124+
$this->remove($name);
125+
$this->add($input, $name);
126+
135127
return $this;
136128
}
137129

@@ -186,16 +178,16 @@ public function remove($name)
186178
*/
187179
public function setData($data)
188180
{
189-
if (!is_array($data) && !$data instanceof Traversable) {
181+
if ($data instanceof Traversable) {
182+
$data = ArrayUtils::iteratorToArray($data);
183+
}
184+
if (!is_array($data)) {
190185
throw new Exception\InvalidArgumentException(sprintf(
191186
'%s expects an array or Traversable argument; received %s',
192187
__METHOD__,
193188
(is_object($data) ? get_class($data) : gettype($data))
194189
));
195190
}
196-
if (is_object($data) && !$data instanceof ArrayAccess) {
197-
$data = ArrayUtils::iteratorToArray($data);
198-
}
199191
$this->data = $data;
200192
$this->populate();
201193
return $this;
@@ -433,6 +425,9 @@ public function getRawValue($name)
433425
));
434426
}
435427
$input = $this->inputs[$name];
428+
if ($input instanceof InputFilterInterface) {
429+
return $input->getRawValues();
430+
}
436431
return $input->getRawValue();
437432
}
438433

src/CollectionInputFilter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ public function getCount()
140140
public function setData($data)
141141
{
142142
$this->data = $data;
143+
144+
return $this;
143145
}
144146

145147
/**

src/InputFilterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface InputFilterInterface extends Countable
2424
* raise an exception for any they cannot process.
2525
* @param null|string $name Name used to retrieve this input
2626
* @return InputFilterInterface
27-
* @throws Exception\InvalidArgumentInterface if unable to handle the input type.
27+
* @throws Exception\InvalidArgumentException if unable to handle the input type.
2828
*/
2929
public function add($input, $name = null);
3030

test/ArrayInputTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ public function testValidationOperatesOnFilteredValue()
7373
$this->input->getFilterChain()->attach($filter);
7474
$validator = new Validator\Digits();
7575
$this->input->getValidatorChain()->attach($validator);
76-
$this->assertTrue($this->input->isValid());
76+
$this->assertTrue(
77+
$this->input->isValid(),
78+
'isValid() value not match. Detail . ' . json_encode($this->input->getMessages())
79+
);
7780
}
7881

7982
public function testSpecifyingMessagesToInputReturnsThoseOnFailedValidation()
@@ -161,7 +164,10 @@ public function testNotAllowEmptyWithFilterConvertsEmptyToNonEmptyIsValid()
161164
->getFilterChain()->attach(new Filter\Callback(function () {
162165
return 'nonempty';
163166
}));
164-
$this->assertTrue($this->input->isValid());
167+
$this->assertTrue(
168+
$this->input->isValid(),
169+
'isValid() value not match. Detail . ' . json_encode($this->input->getMessages())
170+
);
165171
}
166172

167173
public function testMerge($sourceRawValue = 'bazRawValue')

0 commit comments

Comments
 (0)