Example #1
0
 /**
  * Do the validation
  *
  * @param mixed $ip IP Address to check - if null, then use current IP of requestor
  *
  * @return boolean
  */
 protected function validate($ip = null)
 {
     $ip = empty($ip) ? IpUtil::getUserIp() : $ip;
     return Match::on(FTry::with(function () use($ip) {
         return array_reduce($this->netmasks, function (&$result, $cidr) use($ip) {
             return $result || IpUtil::cidrMatch($ip, $cidr);
         }, false);
     }))->Monad_FTry_Success(function ($value) {
         return Match::on(Option::create($value->flatten(), false))->Monad_Option_Some(true)->Monad_Option_None(function () {
             $this->messenger->add(new StringType(self::ERR_MSG1));
             return false;
         })->value();
     })->Monad_FTry_Failure(function ($e) {
         return Match::on(Option::create(strpos($e->value()->getMessage(), 'cidr'), false))->Monad_Option_Some(function () {
             $this->messenger->add(new StringType(self::ERR_MSG2));
             return false;
         })->Monad_Option_None(function () {
             $this->messenger->add(new StringType(self::ERR_MSG1));
             return false;
         })->value();
     })->value();
 }
Example #2
0
 /**
  * @expectedException \Chippyash\Validation\Exceptions\InvalidParameterException
  */
 public function testCidrMatchWillThrowExceptionForInvalidCidr()
 {
     IpUtil::cidrMatch('192.168.10.1', 'foo');
 }