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

Commit 73fccd8

Browse files
committed
Merge branch 'develop'
Merging develop to master in preparation for 2.6.0.
2 parents 97de7e5 + 7b94efe commit 73fccd8

21 files changed

+1101
-265
lines changed

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,23 @@ matrix:
2222
env:
2323
- EXECUTE_CS_CHECK=true
2424
- EXECUTE_HOSTNAME_CHECK=true
25+
- php: 5.5
26+
env:
27+
- SERVICE_MANAGER_VERSION="^2.7.5"
2528
- php: 5.6
2629
env:
2730
- EXECUTE_TEST_COVERALLS=true
31+
- php: 5.6
32+
env:
33+
- SERVICE_MANAGER_VERSION="^2.7.5"
2834
- php: 7
35+
- php: 7
36+
env:
37+
- SERVICE_MANAGER_VERSION="^2.7.5"
2938
- php: hhvm
39+
- php: hhvm
40+
env:
41+
- SERVICE_MANAGER_VERSION="^2.7.5"
3042
allow_failures:
3143
- php: hhvm
3244

@@ -38,6 +50,9 @@ before_install:
3850
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
3951
- composer self-update
4052
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
53+
- if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi
54+
- if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0.3" ; fi
55+
- if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer remove --dev --no-update zendframework/zend-db zendframework/zend-session ; fi
4156

4257
install:
4358
- travis_retry composer install --no-interaction --ignore-platform-reqs

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 2.6.0 - TBD
6+
7+
### Added
8+
9+
- [#18](https://github.com/zendframework/zend-validator/pull/18) adds a `GpsPoint`
10+
validator for validating GPS coordinates.
11+
- [#47](https://github.com/zendframework/zend-validator/pull/47) adds two new
12+
classes, `Zend\Validator\Isbn\Isbn10` and `Isbn13`; these classes are the
13+
result of an extract class refactoring, and contain the logic specific to
14+
calcualting the checksum for each ISBN style. `Zend\Validator\Isbn` now
15+
instantiates the appropriate one and invokes it.
16+
- [#46](https://github.com/zendframework/zend-validator/pull/46) updates
17+
`Zend\Validator\Db\AbstractDb` to implement `Zend\Db\Adapter\AdapterAwareInterface`,
18+
by composing `Zend\Db\Adapter\AdapterAwareTrait`.
19+
20+
### Deprecated
21+
22+
- Nothing.
23+
24+
### Removed
25+
26+
- [#55](https://github.com/zendframework/zend-validator/pull/55) removes some
27+
checks for `safe_mode` within the `MimeType` validator, as `safe_mode` became
28+
obsolete starting with PHP 5.4.
29+
30+
### Fixed
31+
32+
- [#45](https://github.com/zendframework/zend-validator/pull/45) fixes aliases
33+
mapping the deprecated `Float` and `Int` validators to their `Is*` counterparts.
34+
- [#49](https://github.com/zendframework/zend-validator/pull/49)
35+
[#50](https://github.com/zendframework/zend-validator/pull/50), and
36+
[#51](https://github.com/zendframework/zend-validator/pull/51) update the
37+
code to be forwards-compatible with zend-servicemanager and zend-stdlib v3.
38+
- [#56](https://github.com/zendframework/zend-validator/pull/56) fixes the regex
39+
in the `Ip` validator to escape `.` characters used as IP delimiters.
40+
541
## 2.5.5 - TBD
642

743
### Added

composer.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414
},
1515
"require": {
1616
"php": "^5.5 || ^7.0",
17-
"zendframework/zend-stdlib": "~2.5"
17+
"zendframework/zend-stdlib": "^2.7 || ^3.0",
18+
"container-interop/container-interop": "^1.1"
1819
},
1920
"require-dev": {
20-
"zendframework/zend-cache": "~2.5",
21-
"zendframework/zend-config": "~2.5",
22-
"zendframework/zend-db": "~2.5",
23-
"zendframework/zend-filter": "~2.5",
24-
"zendframework/zend-http": "~2.5",
25-
"zendframework/zend-i18n": "~2.5",
26-
"zendframework/zend-math": "~2.5",
27-
"zendframework/zend-servicemanager": "~2.5",
28-
"zendframework/zend-session": "~2.5",
29-
"zendframework/zend-uri": "~2.5",
21+
"zendframework/zend-cache": "^2.6.1",
22+
"zendframework/zend-config": "^2.6",
23+
"zendframework/zend-db": "^2.5",
24+
"zendframework/zend-filter": "^2.6",
25+
"zendframework/zend-http": "^2.5.4",
26+
"zendframework/zend-i18n": "^2.6",
27+
"zendframework/zend-math": "^2.6",
28+
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
29+
"zendframework/zend-session": "^2.5",
30+
"zendframework/zend-uri": "^2.5",
3031
"fabpot/php-cs-fixer": "1.7.*",
31-
"phpunit/PHPUnit": "~4.0"
32+
"phpunit/PHPUnit": "^4.0"
3233
},
3334
"suggest": {
3435
"zendframework/zend-db": "Zend\\Db component",

src/Db/AbstractDb.php

100644100755
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use Traversable;
1313
use Zend\Db\Adapter\Adapter as DbAdapter;
14+
use Zend\Db\Adapter\AdapterAwareInterface;
15+
use Zend\Db\Adapter\AdapterAwareTrait;
1416
use Zend\Db\Sql\Select;
1517
use Zend\Db\Sql\Sql;
1618
use Zend\Db\Sql\TableIdentifier;
@@ -21,8 +23,10 @@
2123
/**
2224
* Class for Database record validation
2325
*/
24-
abstract class AbstractDb extends AbstractValidator
26+
abstract class AbstractDb extends AbstractValidator implements AdapterAwareInterface
2527
{
28+
use AdapterAwareTrait;
29+
2630
/**
2731
* Error constants
2832
*/
@@ -64,13 +68,6 @@ abstract class AbstractDb extends AbstractValidator
6468
*/
6569
protected $exclude = null;
6670

67-
/**
68-
* Database adapter to use. If null isValid() will throw an exception
69-
*
70-
* @var \Zend\Db\Adapter\Adapter
71-
*/
72-
protected $adapter = null;
73-
7471
/**
7572
* Provides basic configuration for use with Zend\Validator\Db Validators
7673
* Setting $exclude allows a single record to be excluded from matching.
@@ -166,8 +163,7 @@ public function getAdapter()
166163
*/
167164
public function setAdapter(DbAdapter $adapter)
168165
{
169-
$this->adapter = $adapter;
170-
return $this;
166+
return $this->setDbAdapter($adapter);
171167
}
172168

173169
/**

src/Explode.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Traversable;
1313
use Zend\Stdlib\ArrayUtils;
14+
use Zend\ServiceManager\ServiceManager;
1415

1516
class Explode extends AbstractValidator implements ValidatorPluginManagerAwareInterface
1617
{
@@ -85,7 +86,7 @@ public function setValidatorPluginManager(ValidatorPluginManager $pluginManager)
8586
public function getValidatorPluginManager()
8687
{
8788
if (!$this->pluginManager) {
88-
$this->setValidatorPluginManager(new ValidatorPluginManager());
89+
$this->setValidatorPluginManager(new ValidatorPluginManager(new ServiceManager));
8990
}
9091

9192
return $this->pluginManager;

src/File/MimeType.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,16 @@ public function getMagicFile()
148148
return $this->options['magicFile'];
149149
}
150150

151-
ErrorHandler::start();
152-
$safeMode = ini_get('safe_mode');
153-
ErrorHandler::stop();
154-
155-
if (!($safeMode == 'On' || $safeMode === 1)) {
156-
foreach ($this->magicFiles as $file) {
157-
// suppressing errors which are thrown due to openbase_dir restrictions
158-
try {
159-
$this->setMagicFile($file);
160-
if ($this->options['magicFile'] !== null) {
161-
break;
162-
}
163-
} catch (Exception\ExceptionInterface $e) {
164-
// Intentionally, catch and fall through
165-
}
151+
foreach ($this->magicFiles as $file) {
152+
try {
153+
$this->setMagicFile($file);
154+
} catch (Exception\ExceptionInterface $e) {
155+
// suppressing errors which are thrown due to open_basedir restrictions
156+
continue;
157+
}
158+
159+
if ($this->options['magicFile'] !== null) {
160+
return $this->options['magicFile'];
166161
}
167162
}
168163

src/GpsPoint.php

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace Zend\Validator;
11+
12+
final class GpsPoint extends AbstractValidator
13+
{
14+
15+
const OUT_OF_BOUNDS = 'gpsPointOutOfBounds';
16+
const CONVERT_ERROR = 'gpsPointConvertError';
17+
const INCOMPLETE_COORDINATE = 'gpsPointIncompleteCoordinate';
18+
19+
/**
20+
* @var array
21+
*/
22+
protected $messageTemplates = [
23+
'gpsPointOutOfBounds' => '%value% is out of Bounds.',
24+
'gpsPointConvertError' => '%value% can not converted into a Decimal Degree Value.',
25+
'gpsPointIncompleteCoordinate' => '%value% did not provided a complete Coordinate',
26+
];
27+
28+
/**
29+
* Returns true if and only if $value meets the validation requirements
30+
*
31+
* If $value fails validation, then this method returns false, and
32+
* getMessages() will return an array of messages that explain why the
33+
* validation failed.
34+
*
35+
* @param mixed $value
36+
* @return bool
37+
* @throws Exception\RuntimeException If validation of $value is impossible
38+
*/
39+
public function isValid($value)
40+
{
41+
if (strpos($value, ',') === false) {
42+
$this->error(GpsPoint::INCOMPLETE_COORDINATE, $value);
43+
return false;
44+
}
45+
46+
list($lat, $long) = explode(',', $value);
47+
48+
if ($this->isValidCoordinate($lat, 90.0000) && $this->isValidCoordinate($long, 180.000)) {
49+
return true;
50+
}
51+
52+
return false;
53+
}
54+
55+
/**
56+
* @param string $value
57+
* @param $maxBoundary
58+
* @return bool
59+
*/
60+
private function isValidCoordinate($value, $maxBoundary)
61+
{
62+
$this->value = $value;
63+
64+
$value = $this->removeWhiteSpace($value);
65+
if ($this->isDMSValue($value)) {
66+
$value = $this->convertValue($value);
67+
} else {
68+
$value = $this->removeDegreeSign($value);
69+
}
70+
71+
if ($value === false || $value === null) {
72+
$this->error(self::CONVERT_ERROR);
73+
return false;
74+
}
75+
76+
$doubleLatitude = (double)$value;
77+
78+
if ($doubleLatitude <= $maxBoundary && $doubleLatitude >= $maxBoundary * -1) {
79+
return true;
80+
}
81+
82+
$this->error(self::OUT_OF_BOUNDS);
83+
return false;
84+
}
85+
86+
/**
87+
* Determines if the give value is a Degrees Minutes Second Definition
88+
*
89+
* @param $value
90+
* @return bool
91+
*/
92+
private function isDMSValue($value)
93+
{
94+
return preg_match('/([°\'"]+[NESW])/', $value) > 0;
95+
}
96+
97+
98+
/**
99+
* @param string $value
100+
* @return bool|string
101+
*/
102+
private function convertValue($value)
103+
{
104+
$matches = [];
105+
$result = preg_match_all('/(\d{1,3})°(\d{1,2})\'(\d{1,2}[\.\d]{0,6})"[NESW]/i', $value, $matches);
106+
107+
if ($result === false || $result === 0) {
108+
return false;
109+
}
110+
111+
return $matches[1][0] + $matches[2][0]/60 + ((double)$matches[3][0])/3600;
112+
}
113+
114+
/**
115+
* @param string $value
116+
* @return string
117+
*/
118+
private function removeWhiteSpace($value)
119+
{
120+
return preg_replace('/\s/', '', $value);
121+
}
122+
123+
/**
124+
* @param string $value
125+
* @return string
126+
*/
127+
private function removeDegreeSign($value)
128+
{
129+
return str_replace('°', '', $value);
130+
}
131+
}

src/Isbn.php

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/**
33
* Zend Framework (http://framework.zend.com/)
44
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @link http://github.com/zendframework/zend-validator for the canonical source repository
6+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
77
* @license http://framework.zend.com/license/new-bsd New BSD License
88
*/
99

@@ -101,45 +101,21 @@ public function isValid($value)
101101

102102
switch ($this->detectFormat()) {
103103
case self::ISBN10:
104-
// sum
105-
$isbn10 = str_replace($this->getSeparator(), '', $value);
106-
$sum = 0;
107-
for ($i = 0; $i < 9; $i++) {
108-
$sum += (10 - $i) * $isbn10{$i};
109-
}
110-
111-
// checksum
112-
$checksum = 11 - ($sum % 11);
113-
if ($checksum == 11) {
114-
$checksum = '0';
115-
} elseif ($checksum == 10) {
116-
$checksum = 'X';
117-
}
104+
$isbn = new Isbn\Isbn10();
118105
break;
119106

120107
case self::ISBN13:
121-
// sum
122-
$isbn13 = str_replace($this->getSeparator(), '', $value);
123-
$sum = 0;
124-
for ($i = 0; $i < 12; $i++) {
125-
if ($i % 2 == 0) {
126-
$sum += $isbn13{$i};
127-
} else {
128-
$sum += 3 * $isbn13{$i};
129-
}
130-
}
131-
// checksum
132-
$checksum = 10 - ($sum % 10);
133-
if ($checksum == 10) {
134-
$checksum = '0';
135-
}
108+
$isbn = new Isbn\Isbn13();
136109
break;
137110

138111
default:
139112
$this->error(self::NO_ISBN);
140113
return false;
141114
}
142115

116+
$value = str_replace($this->getSeparator(), '', $value);
117+
$checksum = $isbn->getChecksum($value);
118+
143119
// validate
144120
if (substr($this->getValue(), -1) != $checksum) {
145121
$this->error(self::NO_ISBN);

0 commit comments

Comments
 (0)