LocateIPRequest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service
  17. * @subpackage DeveloperGarden
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Service_DeveloperGarden_Request_RequestAbstract
  24. */
  25. require_once 'Zend/Service/DeveloperGarden/Request/RequestAbstract.php';
  26. /**
  27. * @see Zend_Service_DeveloperGarden_IpLocation_IpAddress
  28. */
  29. require_once 'Zend/Service/DeveloperGarden/IpLocation/IpAddress.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Service
  33. * @subpackage DeveloperGarden
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @author Marco Kaiser
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. class Zend_Service_DeveloperGarden_Request_IpLocation_LocateIPRequest
  39. extends Zend_Service_DeveloperGarden_Request_RequestAbstract
  40. {
  41. /**
  42. * the ip addresses to lookup for
  43. *
  44. * @var Zend_Service_DeveloperGarden_Request_IpLocation_IpAddress
  45. */
  46. public $address = null;
  47. /**
  48. * the account
  49. *
  50. * @var string
  51. */
  52. public $account = null;
  53. /**
  54. * constructor give them the environment
  55. *
  56. * @param integer $environment
  57. * @param Zend_Service_DeveloperGarden_IpLocation_IpAddress|array $ip
  58. *
  59. * @return Zend_Service_DeveloperGarden_Request_RequestAbstract
  60. */
  61. public function __construct($environment, $ip = null)
  62. {
  63. parent::__construct($environment);
  64. if ($ip !== null) {
  65. $this->setIp($ip);
  66. }
  67. }
  68. /**
  69. * sets new ip or array of ips
  70. *
  71. * @param Zend_Service_DeveloperGarden_IpLocation_IpAddress|array $ip
  72. *
  73. * @return Zend_Service_DeveloperGarden_Request_IpLocation_LocateIPRequest
  74. */
  75. public function setIp($ip)
  76. {
  77. if ($ip instanceof Zend_Service_DeveloperGarden_IpLocation_IpAddress) {
  78. $this->address[] = array(
  79. 'ipType' => $ip->getVersion(),
  80. 'ipAddress' => $ip->getIp(),
  81. );
  82. return $this;
  83. }
  84. if (is_array($ip)) {
  85. foreach ($ip as $ipObject) {
  86. if (!$ipObject instanceof Zend_Service_DeveloperGarden_IpLocation_IpAddress
  87. && !is_string($ipObject)
  88. ) {
  89. require_once 'Zend/Service/DeveloperGarden/Request/Exception.php';
  90. throw new Zend_Service_DeveloperGarden_Request_Exception(
  91. 'Not a valid Ip Address object found.'
  92. );
  93. }
  94. $this->setIp($ipObject);
  95. }
  96. return $this;
  97. }
  98. if (!is_string($ip)) {
  99. require_once 'Zend/Service/DeveloperGarden/Request/Exception.php';
  100. throw new Zend_Service_DeveloperGarden_Request_Exception('Not a valid Ip Address object found.');
  101. }
  102. return $this->setIp(new Zend_Service_DeveloperGarden_IpLocation_IpAddress($ip));
  103. }
  104. }