public function vote(TokenInterface $token, $object, array $attributes)
 {
     $request = $this->getRequest();
     if (!$request) {
         throw new \Exception('No request found.');
     }
     $from = IpConverter::fromIpToHex($request->getClientIp());
     $env = $this->getEnvironment();
     $ips = $this->getIpManager()->findIpAddress($from, $env);
     $ranges = $this->getRangeManager()->findByIpAddress($from, $env);
     if (count($ips) === 0 && count($ranges) === 0) {
         return VoterInterface::ACCESS_ABSTAIN;
     }
     foreach ($ips as $ip) {
         if ($ip->isAuthorized()) {
             return VoterInterface::ACCESS_GRANTED;
         }
     }
     foreach ($ranges as $range) {
         if ($range->isAuthorized()) {
             return VoterInterface::ACCESS_GRANTED;
         }
     }
     return VoterInterface::ACCESS_DENIED;
 }
Esempio n. 2
0
 public function setEndIp($end_ip)
 {
     $this->end_ip = IpConverter::fromIpToHex($end_ip);
     return $this;
 }
Esempio n. 3
0
 public function setIp($ip)
 {
     $this->ip = IpConverter::fromIpToHex($ip);
     return $this;
 }