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

Commit

Permalink
Merge remote-tracking branch 'zf2/master' into feature/doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 316 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

23 changes: 13 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
{
"name": "zendframework/zend-input-filter",
"description": "Zend\\InputFilter component",
"name": "zendframework/zend-inputfilter",
"description": " ",
"license": "BSD-3-Clause",
"keywords": [
"zf2",
"input-filter"
"inputfilter"
],
"autoload": {
"psr-4": {
"Zend\\InputFilter\\": "src/"
"Zend\\InputFilter": "src/"
}
},
"require": {
"php": ">=5.3.23"
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
"php": ">=5.3.3",
"zendframework/zend-filter": "self.version",
"zendframework/zend-validator": "self.version",
"zendframework/zend-stdlib": "self.version"
},
"homepage": "/~https://github.com/zendframework/zend-input-filter",
"autoload-dev": {
"psr-4": {
"ZendTest\\InputFilter\\": "test/"
}
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
}
}
60 changes: 36 additions & 24 deletions src/BaseInputFilter.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InputFilter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_InputFilter
*/

namespace Zend\InputFilter;
Expand All @@ -29,8 +19,6 @@
* should a message be returned? if so, what message?
* @category Zend
* @package Zend_InputFilter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class BaseInputFilter implements InputFilterInterface
{
Expand All @@ -54,9 +42,10 @@ public function count()

/**
* Add an input to the input filter
*
* @param InputInterface|InputFilterInterface $input
* @param null|string $name Name used to retrieve this input
*
* @param InputInterface|InputFilterInterface $input
* @param null|string $name Name used to retrieve this input
* @throws Exception\InvalidArgumentException
* @return InputFilterInterface
*/
public function add($input, $name = null)
Expand All @@ -74,6 +63,13 @@ public function add($input, $name = null)
if (is_null($name) || $name === '') {
$name = $input->getName();
}

if (isset($this->inputs[$name]) && $this->inputs[$name] instanceof InputInterface) {
// The element already exists, so merge the config. Please note that the order is important (already existing
// input is merged with the parameter given)
$input->merge($this->inputs[$name]);
}

$this->inputs[$name] = $input;
return $this;
}
Expand Down Expand Up @@ -149,6 +145,7 @@ public function isValid()
$valid = true;

$inputs = $this->validationGroup ?: array_keys($this->inputs);
//var_dump($inputs);
foreach ($inputs as $name) {
$input = $this->inputs[$name];
if (!array_key_exists($name, $this->data) || (is_string($this->data[$name]) && strlen($this->data[$name]) === 0)) {
Expand All @@ -167,8 +164,7 @@ public function isValid()
// make sure we have a value (empty) for validation
$this->data[$name] = '';
}

$value = $this->data[$name];

if ($input instanceof InputFilterInterface) {
if (!$input->isValid()) {
$this->invalidInputs[$name] = $input;
Expand Down Expand Up @@ -219,14 +215,30 @@ public function setValidationGroup($name)
}

if (is_array($name)) {
$this->validateValidationGroup($name);
$this->validationGroup = $name;
$inputs = array();
foreach ($name as $key => $value) {
if (!$this->has($key)) {
$inputs[] = $value;
} else {
$inputs[] = $key;

// Recursively populate validation groups for sub input filters
$this->inputs[$key]->setValidationGroup($value);
}
}

if (!empty($inputs)) {
$this->validateValidationGroup($inputs);
$this->validationGroup = $inputs;
}

return $this;
}

$inputs = func_get_args();
$this->validateValidationGroup($inputs);
$this->validationGroup = $inputs;

return $this;
}

Expand Down
25 changes: 6 additions & 19 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InputFilter
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_InputFilter
*/

namespace Zend\InputFilter\Exception;
Expand All @@ -25,8 +14,6 @@
* @category Zend
* @package Zend_InputFilter
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface ExceptionInterface
{}
{}
23 changes: 5 additions & 18 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InputFilter
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_InputFilter
*/

namespace Zend\InputFilter\Exception;
Expand All @@ -25,8 +14,6 @@
* @category Zend
* @package Zend_InputFilter
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class InvalidArgumentException extends \InvalidArgumentException implements
ExceptionInterface
Expand Down
23 changes: 5 additions & 18 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InputFilter
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_InputFilter
*/

namespace Zend\InputFilter\Exception;
Expand All @@ -25,8 +14,6 @@
* @category Zend
* @package Zend_InputFilter
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class RuntimeException extends \RuntimeException implements ExceptionInterface
{}
24 changes: 6 additions & 18 deletions src/Factory.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InputFilter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_InputFilter
*/

namespace Zend\InputFilter;

use Traversable;
use Zend\Filter\FilterChain;
use Zend\Stdlib\ArrayUtils;
use Zend\Validator\ValidatorInterface;
use Zend\Validator\ValidatorChain;
use Zend\Validator\ValidatorInterface;

/**
* @category Zend
* @package Zend_InputFilter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Factory
{
Expand Down
44 changes: 26 additions & 18 deletions src/Input.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InputFilter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_InputFilter
*/

namespace Zend\InputFilter;
Expand All @@ -26,8 +16,6 @@
/**
* @category Zend
* @package Zend_InputFilter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Input implements InputInterface
{
Expand Down Expand Up @@ -95,7 +83,6 @@ public function setValue($value)
return $this;
}


public function allowEmpty()
{
return $this->allowEmpty;
Expand All @@ -106,6 +93,11 @@ public function breakOnFailure()
return $this->breakOnFailure;
}

public function getErrorMessage()
{
return $this->errorMessage;
}

public function getFilterChain()
{
if (!$this->filterChain) {
Expand Down Expand Up @@ -143,6 +135,22 @@ public function getValue()
return $filter->filter($this->value);
}

public function merge(InputInterface $input)
{
$this->setAllowEmpty($input->allowEmpty());
$this->setBreakOnFailure($input->breakOnFailure());
$this->setErrorMessage($input->getErrorMessage());
$this->setName($input->getName());
$this->setRequired($input->isRequired());
$this->setValue($input->getValue());

$filterChain = $input->getFilterChain();
$this->getFilterChain()->merge($filterChain);

$validatorChain = $input->getValidatorChain();
$this->getValidatorChain()->merge($validatorChain);
}

public function isValid($context = null)
{
$this->injectNotEmptyValidator();
Expand Down
Loading

0 comments on commit da15c07

Please sign in to comment.