Esempio n. 1
0
 /**
  * @param Domain $domain
  * @return Operation
  * @throws APIException
  * @throws \APIException
  */
 public function register(Domain $domain)
 {
     $fdqn = $domain->getFqdn();
     $gandi = $this->gandi->getProxy('domain');
     //test if the owner can register the domain
     if (!$this->gandi->getProxy('contact')->can_associate_domain($this->api_key, $domain->getOwnerContact()->getHandle(), array('domain' => $fdqn))) {
         throw new \APIException("This contact cannot register this domain.");
     }
     //if no DNS servers defined, add servers from the configuration file
     if (count($domain->getNameservers()) < 1 && count($this->default_nameservers) > 0) {
         foreach ($this->default_nameservers as $ns) {
             $domain->addNameserver($ns);
         }
     }
     //add default admin handle if not set
     if (null == $domain->getAdminContact() && array_key_exists('admin', $this->default_handles)) {
         $domain->setAdminContact(new Contact($this->default_handles['admin']));
     }
     //add default bill handle if not set
     if (null == $domain->getBillContact() && array_key_exists('bill', $this->default_handles)) {
         $domain->setBillContact(new Contact($this->default_handles['bill']));
     }
     //add default tech handle if not set
     if (null == $domain->getTechContact() && array_key_exists('tech', $this->default_handles)) {
         $domain->setTechContact(new Contact($this->default_handles['tech']));
     }
     //add default owner handle if not set
     if (null == $domain->getOwnerContact() && array_key_exists('owner', $this->default_handles)) {
         $domain->setOwnerContact(new Contact($this->default_handles['owner']));
     }
     $data = $domain->toGandiArray();
     $result = $gandi->create($this->api_key, $fdqn, $data);
     if ($result['last_error']) {
         throw new APIException($result['last_error']);
     }
     return new Operation($result);
 }