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

Commit

Permalink
Merge branch 'master' into acceptHandling
Browse files Browse the repository at this point in the history
Conflicts:
	library/Zend/Http/Header/AbstractAccept.php
	library/Zend/Http/Header/AcceptEncoding.php
	library/Zend/Http/Header/AcceptLanguage.php
	tests/Zend/Http/Header/AcceptCharsetTest.php
	tests/Zend/Http/Header/AcceptEncodingTest.php
	tests/Zend/Http/Header/AcceptLanguageTest.php
	tests/Zend/Http/Header/AcceptTest.php
  • Loading branch information
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 147 deletions.
1 change: 0 additions & 1 deletion src/AbstractValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Traversable;
use Zend\I18n\Translator\Translator;
use Zend\Registry;
use Zend\Stdlib\ArrayUtils;
use Zend\Validator\Exception\InvalidArgumentException;

Expand Down
2 changes: 1 addition & 1 deletion src/Csrf.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function getSalt()
/**
* Retrieve CSRF token
*
* If no CSRF token currently exists, or should be regenrated,
* If no CSRF token currently exists, or should be regenrated,
* generates one.
*
* @param bool $regenerate default false
Expand Down
6 changes: 3 additions & 3 deletions src/DateStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected function convertToDateTime($param)
if (is_int($param)) {
// Convert from timestamp
$dateObj = date_create("@$param");
} else if (is_string($param)) {
} elseif (is_string($param)) {
// Custom week format support
if (strpos($this->getFormat(), 'Y-\WW') === 0
&& preg_match('/^([0-9]{4})\-W([0-9]{2})/', $param, $matches)
Expand Down Expand Up @@ -339,9 +339,9 @@ public function isValid($value)
&& 0 == $diffParts['minutes'] && 0 == $diffParts['seconds']
) {
return true;
} else if ('minutes' === $intervalUnit && 0 == $diffParts['seconds']) {
} elseif ('minutes' === $intervalUnit && 0 == $diffParts['seconds']) {
return true;
} else if ('seconds' === $intervalUnit) {
} elseif ('seconds' === $intervalUnit) {
return true;
}
}
Expand Down
71 changes: 20 additions & 51 deletions src/InArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

namespace Zend\Validator;

use Traversable;
use Zend\Stdlib\ArrayUtils;
use RecursiveArrayIterator;
use RecursiveIteratorIterator;

/**
* @category Zend
* @package Zend_Validate
* @category Zend
* @package Zend_Validate
*/
class InArray extends AbstractValidator
{
Expand All @@ -25,7 +25,7 @@ class InArray extends AbstractValidator
* @var array
*/
protected $messageTemplates = array(
self::NOT_IN_ARRAY => "The input was not found in the haystack",
self::NOT_IN_ARRAY => 'The input was not found in the haystack',
);

/**
Expand All @@ -49,56 +49,17 @@ class InArray extends AbstractValidator
*/
protected $recursive = false;

/**
* Sets validator options
*
* @param array|Traversable $options
* @throws Exception\InvalidArgumentException
*/
public function __construct($options = null)
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
if (!is_array($options)) {
throw new Exception\InvalidArgumentException('Array expected as parameter');
} else {
$count = func_num_args();
$temp = array();
if ($count > 1) {
$temp['haystack'] = func_get_arg(0);
$temp['strict'] = func_get_arg(1);
$options = $temp;
} else {
$temp = func_get_arg(0);
if (!array_key_exists('haystack', $options)) {
$options = array();
$options['haystack'] = $temp;
} else {
$options = $temp;
}
}
}

$this->setHaystack($options['haystack']);
if (array_key_exists('strict', $options)) {
$this->setStrict($options['strict']);
}

if (array_key_exists('recursive', $options)) {
$this->setRecursive($options['recursive']);
}

parent::__construct();
}

/**
* Returns the haystack option
*
* @return mixed
* @throws Exception\RuntimeException if haystack option is not set
*/
public function getHaystack()
{
if ($this->haystack == null) {
throw new Exception\RuntimeException('haystack option is mandatory');
}
return $this->haystack;
}

Expand Down Expand Up @@ -163,14 +124,22 @@ public function setRecursive($recursive)
* option is true, then the type of $value is also checked.
*
* @param mixed $value
* @throws Exception\RuntimeException If 0 is present in the haystack and strict mode is disabled.
* See {@link http://php.net/manual/function.in-array.php#104501}
* @return boolean
*/
public function isValid($value)
{
if (!$this->strict && in_array(0, $this->getHaystack(), true)) {
// Strings are treated as 0 integer by PHP
// ZF2-337 http://php.net/manual/function.in-array.php#104501
throw new Exception\RuntimeException('Comparisons with 0 are only possible in strict mode');
}

$this->setValue($value);
if ($this->getRecursive()) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->haystack));
foreach($iterator as $element) {
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->getHaystack()));
foreach ($iterator as $element) {
if ($this->strict) {
if ($element === $value) {
return true;
Expand All @@ -180,7 +149,7 @@ public function isValid($value)
}
}
} else {
if (in_array($value, $this->haystack, $this->strict)) {
if (in_array($value, $this->getHaystack(), $this->strict)) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/StaticValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class StaticValidator

/**
* Set plugin manager to use for locating validators
*
*
* @param ValidatorPluginManager|null $plugins
* @return void
*/
Expand All @@ -38,7 +38,7 @@ public static function setPluginManager(ValidatorPluginManager $plugins = null)

/**
* Get plugin manager for locating validators
*
*
* @return ValidatorPluginManager
*/
public static function getPluginManager()
Expand Down
1 change: 0 additions & 1 deletion test/DateStepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use DateInterval;

/**
* @see \Zend\Validator\DateStep
* @category Zend
* @package Zend_Validator
* @subpackage UnitTests
Expand Down
5 changes: 2 additions & 3 deletions test/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Zend\Validator;

/**
* @see Zend_Validator_Date
* @category Zend
* @package Zend_Validator
* @subpackage UnitTests
Expand Down Expand Up @@ -119,8 +118,8 @@ public function testUseManualFormat()
$this->assertFalse($this->validator->setFormat('d/m/Y')->isValid('2008/10/22'));
$this->assertTrue($this->validator->setFormat('d/m/Y')->isValid('22/10/08'));
$this->assertFalse($this->validator->setFormat('d/m/Y')->isValid('22/10'));
// Omitting the following assertion, as it varies from 5.3.3 to 5.3.11,
// and there is no indication in the PHP changelog as to when or why it
// Omitting the following assertion, as it varies from 5.3.3 to 5.3.11,
// and there is no indication in the PHP changelog as to when or why it
// may have changed. Leaving for posterity, to indicate original expectation.
// $this->assertFalse($this->validator->setFormat('s')->isValid(0));
}
Expand Down
Loading

0 comments on commit 8785f25

Please sign in to comment.