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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
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 232 additions and 390 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"
}
}
112 changes: 62 additions & 50 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 @@ -25,12 +15,10 @@
use Zend\Stdlib\ArrayUtils;

/**
* @todo How should we deal with required input when data is missing?
* @todo How should we deal with required input when data is missing?
* 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 @@ -44,7 +32,7 @@ class BaseInputFilter implements InputFilterInterface
* Countable: number of inputs in this input filter
*
* Only details the number of direct children.
*
*
* @return int
*/
public function count()
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 @@ -71,17 +60,24 @@ public function add($input, $name = null)
));
}

if (empty($name)) {
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;
}

/**
* Retrieve a named input
*
* @param string $name
*
* @param string $name
* @return InputInterface|InputFilterInterface
*/
public function get($name)
Expand All @@ -98,8 +94,8 @@ public function get($name)

/**
* Test if an input or input filter by the given name is attached
*
* @param string $name
*
* @param string $name
* @return bool
*/
public function has($name)
Expand All @@ -109,8 +105,8 @@ public function has($name)

/**
* Set data to use when validating and filtering
*
* @param array|Traversable $data
*
* @param array|Traversable $data
* @return InputFilterInterface
*/
public function setData($data)
Expand All @@ -132,7 +128,7 @@ public function setData($data)

/**
* Is the data set valid?
*
*
* @return bool
*/
public function isValid()
Expand All @@ -147,10 +143,11 @@ public function isValid()
$this->validInputs = array();
$this->invalidInputs = array();
$valid = true;

$inputs = $this->validationGroup ?: array_keys($this->inputs);
//var_dump($inputs);
foreach ($inputs as $name) {
$input = $this->inputs[$name];
$input = $this->inputs[$name];
if (!array_key_exists($name, $this->data) || (is_string($this->data[$name]) && strlen($this->data[$name]) === 0)) {
if($input instanceof InputInterface) {
// - test if input is required
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 @@ -207,8 +203,8 @@ public function isValid()
*
* Implementations should allow passing a single array value, or multiple arguments,
* each specifying a single input.
*
* @param mixed $name
*
* @param mixed $name
* @return InputFilterInterface
*/
public function setValidationGroup($name)
Expand All @@ -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 All @@ -235,7 +247,7 @@ public function setValidationGroup($name)
*
* Implementations should return an associative array of name/input pairs
* that failed validation.
*
*
* @return InputInterface[]
*/
public function getInvalidInput()
Expand All @@ -248,7 +260,7 @@ public function getInvalidInput()
*
* Implementations should return an associative array of name/input pairs
* that passed validation.
*
*
* @return InputInterface[]
*/
public function getValidInput()
Expand All @@ -258,8 +270,8 @@ public function getValidInput()

/**
* Retrieve a value from a named input
*
* @param string $name
*
* @param string $name
* @return mixed
*/
public function getValue($name)
Expand All @@ -280,7 +292,7 @@ public function getValue($name)
*
* List should be an associative array, with the values filtered. If
* validation failed, this should raise an exception.
*
*
* @return array
*/
public function getValues()
Expand All @@ -301,8 +313,8 @@ public function getValues()

/**
* Retrieve a raw (unfiltered) value from a named input
*
* @param string $name
*
* @param string $name
* @return mixed
*/
public function getRawValue($name)
Expand All @@ -323,7 +335,7 @@ public function getRawValue($name)
*
* List should be an associative array of named input/value pairs,
* with the values unfiltered.
*
*
* @return array
*/
public function getRawValues()
Expand All @@ -344,7 +356,7 @@ public function getRawValues()
*
* Should return an associative array of named input/message list pairs.
* Pairs should only be returned for inputs that failed validation.
*
*
* @return array
*/
public function getMessages()
Expand All @@ -358,8 +370,8 @@ public function getMessages()

/**
* Ensure all names of a validation group exist as input in the filter
*
* @param array $inputs
*
* @param array $inputs
* @return void
* @throws Exception\InvalidArgumentException
*/
Expand All @@ -377,7 +389,7 @@ protected function validateValidationGroup(array $inputs)

/**
* Populate the values of all attached inputs
*
*
* @return void
*/
protected function populate()
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
{}
{}
Loading

0 comments on commit be0deed

Please sign in to comment.