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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Promote develop to master, becoming the next stable release.
  • Loading branch information
weierophinney committed Mar 12, 2014
165 parents 8440392 + 0fa89e9 + b904b9d + 265e07a + 7198368 + 1214d4a + 2a94048 + e55039d + b3e6575 + 28a083e + f57823e + 8e9d237 + 4eaa835 + 1d32d23 + bfc0ac0 + 0337874 + ac4e5a4 + 74ad4e1 + 8037ddd + c91b8cb + 442a604 + ce86130 + 6a17c00 + 3be35a1 + b101693 + 38a8855 + 2503264 + 1330305 + c63994b + 0cebe75 + 88437dd + 335a7e0 + 49f818c + 94c6248 + babc2b3 + c5537ad + a278174 + ee91e56 + f730475 + e954d31 + aa83987 + 4272527 + 760e014 + 8f9644f + 89ddc85 + ef5a070 + af19258 + 363ebe6 + 774ea64 + db99c7e + fb3727c + d8ea42f + a5c0289 + 9730940 + ebc1a56 + 1d8cf16 + 09b3859 + efe96d1 + acf177c + 7a7f261 + df4c86b + 4d14dd3 + d0b7057 + c858228 + 8855a3f + 956acc6 + 085a083 + 99b3987 + 59e9d17 + edd16d1 + 17ad876 + 401ed50 + f43d222 + 73ebfdd + da15c07 + 4652c73 + 6a7b288 + 93b11b3 + d67242e + be0deed + c16475f + 68c3d64 + 537f455 + e79de85 + 0cbbdec + 3e0855f + a7a27db + a851ed1 + 86bf6e9 + 9fcf3f0 + c6deb01 + 811568b + 7222979 + 61e594a + 3e10b67 + ecabb9a + 8cdd2bc + 779ae47 + 5ef112f + 7ea9722 + e951b83 + 37c7404 + e730f97 + 43752c5 + ba32611 + 7c15be9 + e3a9518 + cc9ba24 + 5fbd138 + 8bab1da + fa276b4 + 3615cdf + 663ba3c + f0e4074 + c39cf5f + bfa79e5 + 3951384 + 428584d + 9dccbe3 + bc78b89 + 918afd4 + 3ed20dd + 03fd3e7 + 105081b + a6837d0 + 45c4355 + ef30a66 + 06503d1 + 870c487 + 178c8e6 + 059662a + 022a3e8 + 2791c44 + e059c77 + 5011c6b + daa0af0 + 064e54f + 6d4c9af + 5b6377d + c18bb7b + 2216b26 + 3edc277 + d0bb055 + 15def87 + 11ffd8b + 1628530 + af75d0c + f2ee090 + 83bf2e2 + 7a23c87 + 8632b61 + 2595c1a + 035e666 + c7d052f + 4f3bc98 + 11befce + f977510 + e7c6c29 + e547c78 + 7b9809d + 8ed3edf + 2619551 + 20df0e3 + f003b92 + 3548cb5 commit 9676012
Show file tree
Hide file tree
Showing 17 changed files with 321 additions and 25 deletions.
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
}
},
"require": {
"php": ">=5.3.3",
"php": ">=5.3.23",
"zendframework/zend-filter": "self.version",
"zendframework/zend-validator": "self.version",
"zendframework/zend-stdlib": "self.version"
},
"require-dev": {
"zendframework/zend-servicemanager": "self.version",
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
},
"suggest": {
"zendframework/zend-servicemanager": "To support plugin manager support"
},
Expand All @@ -31,10 +37,5 @@
"psr-4": {
"ZendTest\\InputFilter\\": "test/"
}
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
}
}
4 changes: 2 additions & 2 deletions src/ArrayInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public function isValid($context = null)
foreach ($values as $value) {
$result = $validator->isValid($value, $context);
if (!$result) {
if ($fallbackValue = $this->getFallbackValue()) {
$this->setValue($fallbackValue);
if ($this->hasFallback()) {
$this->setValue($this->getFallbackValue());
$result = true;
}
break;
Expand Down
11 changes: 10 additions & 1 deletion src/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ protected function validateInputs(array $inputs, array $data = array())
&& $input->isRequired()
&& $input->allowEmpty()
) {
if(!($input instanceOf EmptyContextInterface && $input->continueIfEmpty())) {
if (!($input instanceOf EmptyContextInterface && $input->continueIfEmpty())) {
$this->validInputs[$name] = $input;
continue;
}
Expand Down Expand Up @@ -581,6 +581,15 @@ protected function populate()
// No value; clear value in this input
if ($input instanceof InputFilterInterface) {
$input->setData(array());
if ($input instanceof CollectionInputFilter) {
$input->clearValues();
$input->clearRawValues();
}
continue;
}

if ($input instanceof ArrayInput) {
$input->setValue(array());
continue;
}

Expand Down
26 changes: 26 additions & 0 deletions src/CollectionInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ public function isValid()
$valid = false;
}

if (empty($this->collectionData)) {
$this->clearValues();
$this->clearRawValues();
return $valid;
}

$inputs = $this->validationGroup ?: array_keys($this->inputs);
foreach ($this->collectionData as $key => $data) {
if (!is_array($data)) {
Expand Down Expand Up @@ -267,6 +273,26 @@ public function getRawValues()
return $this->collectionRawValues;
}

/**
* Clear collectionValues
*
* @access public
*/
public function clearValues()
{
return $this->collectionValues = array();
}

/**
* Clear collectionRawValues
*
* @access public
*/
public function clearRawValues()
{
return $this->collectionRawValues = array();
}

/**
* {@inheritdoc}
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ public function createInputFilter($inputFilterSpecification)
if (isset($inputFilterSpecification['count'])) {
$inputFilter->setCount($inputFilterSpecification['count']);
}
if (isset($inputFilterSpecification['required'])) {
$inputFilter->setIsRequired($inputFilterSpecification['required']);
}
return $inputFilter;
}

Expand Down
26 changes: 23 additions & 3 deletions src/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class Input implements InputInterface, EmptyContextInterface
*/
protected $fallbackValue;

/**
* @var bool
*/
protected $hasFallback = false;

public function __construct($name = null)
{
$this->name = $name;
Expand Down Expand Up @@ -173,6 +178,7 @@ public function setValue($value)
public function setFallbackValue($value)
{
$this->fallbackValue = $value;
$this->hasFallback = true;
return $this;
}

Expand Down Expand Up @@ -271,6 +277,20 @@ public function getFallbackValue()
return $this->fallbackValue;
}

/**
* @return bool
*/
public function hasFallback()
{
return $this->hasFallback;
}

public function clearFallbackValue()
{
$this->hasFallback = false;
$this->fallbackValue = null;
}

/**
* @param InputInterface $input
* @return Input
Expand Down Expand Up @@ -308,8 +328,8 @@ public function isValid($context = null)
$validator = $this->getValidatorChain();
$value = $this->getValue();
$result = $validator->isValid($value, $context);
if (!$result && $fallbackValue = $this->getFallbackValue()) {
$this->setValue($fallbackValue);
if (!$result && $this->hasFallback()) {
$this->setValue($this->getFallbackValue());
$result = true;
}

Expand All @@ -325,7 +345,7 @@ public function getMessages()
return (array) $this->errorMessage;
}

if ($this->getFallbackValue()) {
if ($this->hasFallback()) {
return array();
}

Expand Down
35 changes: 34 additions & 1 deletion test/ArrayInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down Expand Up @@ -186,4 +186,37 @@ public function testDoNotInjectNotEmptyValidatorIfAnywhereInChain()
$this->assertEquals(2, count($validators));
$this->assertEquals($notEmptyMock, $validators[1]['instance']);
}

public function dataFallbackValue()
{
return array(
array(
'fallbackValue' => array()
),
array(
'fallbackValue' => array(''),
),
array(
'fallbackValue' => array(null),
),
array(
'fallbackValue' => array('some value'),
),
);
}

/**
* @dataProvider dataFallbackValue
*/
public function testFallbackValue($fallbackValue)
{
$this->input->setFallbackValue($fallbackValue);
$validator = new Validator\Date();
$this->input->getValidatorChain()->attach($validator);
$this->input->setValue(array('123')); // not a date

$this->assertTrue($this->input->isValid());
$this->assertEmpty($this->input->getMessages());
$this->assertSame($fallbackValue, $this->input->getValue());
}
}
19 changes: 18 additions & 1 deletion test/BaseInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down Expand Up @@ -865,6 +865,7 @@ public function testAddingExistingInputWillMergeIntoExisting()

/**
* @group 5270
* @requires extension intl
*/
public function testIsValidWhenValuesSetOnFilters()
{
Expand Down Expand Up @@ -895,4 +896,20 @@ public function testIsValidWhenValuesSetOnFilters()
$this->assertTrue($filter->get('foo')->isValid(), 'Filtered value is not valid');
$this->assertTrue($filter->isValid(), 'Input filter did return value from filter');
}

/**
* @group 5638
*/
public function testPopulateSupportsArrayInputEvenIfDataMissing()
{
$arrayInput = $this->getMock('Zend\InputFilter\ArrayInput');
$arrayInput
->expects($this->once())
->method('setValue')
->with(array());

$filter = new InputFilter();
$filter->add($arrayInput, 'arrayInput');
$filter->setData(array('foo' => 'bar'));
}
}
Loading

0 comments on commit 9676012

Please sign in to comment.