Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IpValidator.php
Go to the documentation of this file.
1 <?php
7 
12 {
16  private $none;
17 
21  private $validIps;
22 
26  private $invalidIps;
27 
36  public function validateIps(array $ips, $noneAllowed)
37  {
38  $this->none = [];
39  $this->validIps = [];
40  $this->invalidIps = [];
41  $messages = [];
42 
43  $this->filterIps($ips);
44 
45  if (sizeof($this->none) > 0 && !$noneAllowed) {
46  $messages[] = "'none' is not allowed";
47  } elseif ($noneAllowed && sizeof($this->none) > 1) {
48  $messages[] = "'none' can be only used once";
49  } elseif ($noneAllowed && sizeof($this->none) > 0 &&
50  (sizeof($this->validIps) > 0 || sizeof($this->invalidIps) > 0)
51  ) {
52  $messages[] = "Multiple values are not allowed when 'none' is used";
53  } else {
54  foreach ($this->invalidIps as $invalidIp) {
55  $messages[] = "Invalid IP $invalidIp";
56  }
57  }
58  return $messages;
59  }
60 
67  private function filterIps(array $ips)
68  {
69  foreach ($ips as $ip) {
70  if (filter_var($ip, FILTER_VALIDATE_IP)) {
71  $this->validIps[] = $ip;
72  } elseif ($ip == 'none') {
73  $this->none[] = $ip;
74  } else {
75  $this->invalidIps[] = $ip;
76  }
77  }
78  }
79 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
validateIps(array $ips, $noneAllowed)
Definition: IpValidator.php:36