PHP code example of tourze / cloudflare-dns-bundle
1. Go to this page and download the library: Download tourze/cloudflare-dns-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/ */
use CloudflareDnsBundle\Entity\IamKey;
$iamKey = new IamKey();
$iamKey->setName('Main Account');
$iamKey->setEmail('[email protected]');
$iamKey->setAccessKey('your-api-key');
$iamKey->setAccountId('your-account-id');
$entityManager->persist($iamKey);
$entityManager->flush();
use CloudflareDnsBundle\Service\DnsRecordService;
use CloudflareDnsBundle\Entity\DnsRecord;
use CloudflareDnsBundle\Enum\DnsRecordType;
class MyService
{
public function __construct(
private DnsRecordService $dnsRecordService
) {}
public function createRecord(): void
{
$record = new DnsRecord();
$record->setDomain($domain);
$record->setType(DnsRecordType::A);
$record->setRecord('subdomain.example.com');
$record->setContent('192.168.1.1');
$record->setTtl(3600);
$record->setProxy(true);
$this->dnsRecordService->syncToRemote($record);
}
}
use CloudflareDnsBundle\EventListener\DnsRecordSyncListener;
use Doctrine\ORM\Events;
class MyListener
{
public function postPersist($args): void
{
$entity = $args->getObject();
if ($entity instanceof DnsRecord) {
// Custom logic after DNS record creation
}
}
}
bash
# Sync DNS analytics for last 24 hours
php bin/console cloudflare:sync-dns-analytics
# Sync analytics for specific time range
php bin/console cloudflare:sync-dns-analytics --since="2024-01-01" --until="2024-01-31"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.