Overview
  • Namespace
  • Class
  • Tree

Namespaces

  • Modulework
    • Modules
      • Http
        • Exceptions
        • Utilities
  • PHP

Classes

  • ArrayCase
  • FileCase
  • HeaderCase
  • HeaderWrapper
  • IpValidator
  • ServerCase

Interfaces

  • ArrayCaseInterface
  • HeaderWrapperInterface
  • IpValidatorInterface
 1 <?php namespace Modulework\Modules\Http\Utilities;
 2 /*
 3  * (c) Christian Gärtner <christiangaertner.film@googlemail.com>
 4  * This file is part of the Modulework Framework
 5  * License: View distributed LICENSE file
 6  */
 7  
 8 
 9 /**
10  * IP Validator
11  * Validates IPv4 and IPv6 address
12  */
13 class IpValidator implements IpValidatorInterface
14 {
15     /**
16      * {@inheritdoc}
17      */
18     public static function all($ip)
19     {
20 
21         $func = false !== strpos($ip, ':') ? 'ipv6': 'ipv4';
22         
23         if (self::isPrivate($ip) || self::isReserved($ip) || self::isBroadcast($ip)) {
24             return false;
25         }
26         return self::$func($ip);
27     }
28 
29     /**
30      * {@inheritdoc}
31      */
32     public static function ipv4($ip)
33     {
34         return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false);
35     }
36 
37     /**
38      * {@inheritdoc}
39      */
40     public static function ipv6($ip)
41     {
42         return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false);
43     }
44 
45     /**
46      * {@inheritdoc}
47      */
48     public static function isPrivate($ip)
49     {
50         if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) {
51             return false;
52         } else {
53             return true;
54         }
55     }
56 
57     /**
58      * {@inheritdoc}
59      */
60     public static function isReserved($ip)
61     {
62         if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) {
63             return false;
64         } else {
65             return true;
66         }
67     }
68 
69     /**
70      * {@inheritdoc}
71      */
72     public static function isBroadcast($ip)
73     {
74         $segments = explode('.', $ip);
75         if (isset($segments[3])) {
76             return ($segments[3] == '0' || $segments[3] == '255');
77         } else {
78             return false;
79         }
80         
81     }
82 }
API documentation generated by ApiGen 2.8.0