PHP code example of edsi-tech / gandi-bundle

1. Go to this page and download the library: Download edsi-tech/gandi-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

edsi-tech / gandi-bundle example snippets


$currentHandle = "MYHANDLE-GANDI";

$domainRepository = $this->get('edsitech_gandi.domain_repository');
$domains_api = $domainRepository->findBy(['handle' => $currentHandle]);
foreach($domains_api as $domain) {
    $fqdn = $domain->getFqdn();
    echo $fqdn.": ".$domain->getExpire()->format('Y-m-d')."\n";
}

use EdsiTech\GandiBundle\Model\Domain;

$fqdn = "example.com";

$domainRepository = $this->get('edsitech_gandi.domain_repository');
$domain = $domainRepository->find($fqdn);

if($domain instanceof Domain) {
    print_r($domain);
}


$gandi = $this->get('edsitech_gandi.domain_availibility');
print_r($gandi->getExtensions());

$domain = "example.com";

$domainAPI = $this->get('edsitech_gandi.domain_availibility');
$domain = idn_to_ascii($domain); //needed for special chars domains 
        
$result = $domainAPI->isAvailable([$domain]); //this is an array, you can pass multiple domains

print_r($result); //the result is also an array, the key is the domain name and the value is the result.

use EdsiTech\GandiBundle\Model\Domain;
use EdsiTech\GandiBundle\Model\Contact;
use EdsiTech\GandiBundle\Model\Operation;
use EdsiTech\GandiBundle\Exception\APIException;

$fqdn = "example.com";
$myHandle = "XYZ-GANDI";

$domain = new Domain($fqdn);
$domain->setDuration(1) //years
       ->setAutorenew(true)
       ->setOwnerContact(new Contact($myHandle))
       ;
//others contact informations are taken from the default_handles config keys.

$domainRepository = $this->get('edsitech_gandi.domain_repository');

try {
    $result = $domainRepository->register($domain);
     
     if($result instanceof Operation) {
         
         echo "Operation in progress";
         
     }

                 
 } catch (APIException $e) {
     
     $message = $e->getMessage();
     
     echo "Error: ".$message;

 }


use EdsiTech\GandiBundle\Model\Operation;

$domain = "example.com";
$authcode = "test";

$domainRepository = $this->get('edsitech_gandi.domain_repository');
$result = $domainRepository->transfert($domain, $authcode);

if($result instanceof Operation) {
    echo "Operation in progress";
}
                

use EdsiTech\GandiBundle\Exception\APIException;

$fqdn = "example.com";

$domainRepository = $this->get('edsitech_gandi.domain_repository');
     
$domain = $domainRepository->find($fqdn);

try {
    $domainRepository->enableAutorenew($domain);
} catch (APIException $e) {

    echo "That's an error";

}

use EdsiTech\GandiBundle\Exception\APIException;

$fqdn = "example.com";

$domainRepository = $this->get('edsitech_gandi.domain_repository');
     
$domain = $domainRepository->find($fqdn);

try {
    $domain->setLock(false);
    $domainRepository->update($domain);
    
} catch (APIException $e) {

    echo "That's an error";

}

use EdsiTech\GandiBundle\Form\ContactType;
use EdsiTech\GandiBundle\Model\Contact;
use EdsiTech\GandiBundle\Exception\APIException;

$contactRepository = $this->get('edsitech_gandi.contact_repository');

$contact = $contactRepository->find($currentHandle);

$form = $this->createForm(new ContactType(), $contact);


//....



if ($form->isValid()) {

    try {

        $result = $contactRepository->persist($contact);
        
                    
    } catch (APIException $e) {
        

		//...

    }
}