示例#1
0
    /**
     * sets new ip or array of ips
     *
     * @param Zend_Service_DeveloperGarden_IpLocation_IpAddress|array $ip
     *
     * @return Zend_Service_DeveloperGarden_Request_IpLocation_LocateIPRequest
     */
    public function setIp($ip)
    {
        if ($ip instanceof Zend_Service_DeveloperGarden_IpLocation_IpAddress) {
            $this->address[] = array(
                'ipType'    => $ip->getVersion(),
                'ipAddress' => $ip->getIp(),
            );
            return $this;
        }

        if (is_array($ip)) {
            foreach ($ip as $ipObject) {
                if (!$ipObject instanceof Zend_Service_DeveloperGarden_IpLocation_IpAddress
                    && !is_string($ipObject)
                ) {
                    require_once 'Zend/Service/DeveloperGarden/Request/Exception.php';
                    throw new Zend_Service_DeveloperGarden_Request_Exception(
                        'Not a valid Ip Address object found.'
                    );
                }
                $this->setIp($ipObject);
            }
            return $this;
        }

        if (!is_string($ip)) {
            require_once 'Zend/Service/DeveloperGarden/Request/Exception.php';
            throw new Zend_Service_DeveloperGarden_Request_Exception('Not a valid Ip Address object found.');
        }

        return $this->setIp(new Zend_Service_DeveloperGarden_IpLocation_IpAddress($ip));
    }
示例#2
0
 /**
  * @expectedException Zend_Service_DeveloperGarden_Exception
  */
 public function testIpAddressVersion()
 {
     $ip = new Zend_Service_DeveloperGarden_IpLocation_IpAddress('127.0.0.1', 4);
     $this->assertNotNull($ip->setVersion(6));
 }