Skip to content

Commit

Permalink
remove ipv4 and ipv6, make ip more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Jul 3, 2015
1 parent eeff667 commit 56437af
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 182 deletions.
2 changes: 0 additions & 2 deletions src/Rule/Locator/ValidateLocator.php
Expand Up @@ -38,8 +38,6 @@ protected function initFactories(array $factories)
'int' => function () { return new Validate\Integer(); },
'inValues' => function () { return new Validate\InValues(); },
'ip' => function () { return new Validate\Ip(); },
'ipv4' => function () { return new Validate\Ipv4(); },
'ipv6' => function () { return new Validate\Ipv6(); },
'isbn' => function () { return new Validate\Isbn(); },
'locale' => function () { return new Validate\Locale(); },
'max' => function () { return new Validate\Max(); },
Expand Down
15 changes: 6 additions & 9 deletions src/Rule/Validate/Ip.php
Expand Up @@ -19,24 +19,21 @@ class Ip
{
/**
*
* Validates that the value is a legal IP address.
* Validates that the value is an IP address.
*
* @param object $subject The subject to be filtered.
*
* @param string $field The subject field name.
*
* @param mixed $flags `FILTER_VALIDATE_IP` flags to pass to filter_var();
* cf. <http://php.net/manual/en/filter.filters.flags.php>.
*
* @return bool True if valid, false if not.
*
*/
public function __invoke($subject, $field)
public function __invoke($subject, $field, $flags = FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6)
{
$value = $subject->$field;

// This validates without regard to reserved or private ranges in both v4 and v6
if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) === false) {
return false;
} else {
return true;
}
return filter_var($value, FILTER_VALIDATE_IP, $flags) !== false;
}
}
42 changes: 0 additions & 42 deletions src/Rule/Validate/Ipv4.php

This file was deleted.

42 changes: 0 additions & 42 deletions src/Rule/Validate/Ipv6.php

This file was deleted.

36 changes: 0 additions & 36 deletions tests/Rule/Validate/Ipv4Test.php

This file was deleted.

51 changes: 0 additions & 51 deletions tests/Rule/Validate/Ipv6Test.php

This file was deleted.

0 comments on commit 56437af

Please sign in to comment.