villaflor/laravel-cloudflare

A Laravel client library for accessing Cloudflare APIs

1.0.0 2021-02-27 20:33 UTC

This package is auto-updated.

Last update: 2024-04-28 22:13:35 UTC


README

Cloudflare library for Laravel. This library is an expansion of the official Cloudflare PHP SDK

68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f76696c6c61666c6f722f6c61726176656c2d636c6f7564666c6172652e7376673f7374796c653d666c6174 68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f76696c6c61666c6f722f6c61726176656c2d636c6f7564666c6172652e7376673f7374796c653d666c6174 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f76696c6c61666c6f722f6c61726176656c2d636c6f7564666c617265 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76696c6c61666c6f722f6c61726176656c2d636c6f7564666c617265

Requirement

  • Cloudflare API token

Installation

In terminal

composer require villaflor/laravel-cloudflare

php artisan vendor:publish --provider="Villaflor\Cloudflare\CloudflareServiceProvider"

In .env file add this line

CLOUDFLARE_API_TOKEN={API token here}

Methods Available

CloudflareDNS

  • addRecord
  • listRecords
  • getRecordDetails
  • getRecordID
  • updateRecordDetails
  • deleteRecord

CloudflareDNSAnalytics

  • getReportTable
  • getReportByTime

CloudflareIps

  • listIPs

CloudflareZone

  • addZone
  • activationCheck
  • pause
  • unpause
  • getZoneById
  • listZones
  • getZoneID
  • getAnalyticsDashboard
  • changeDevelopmentMode
  • getCachingLevel
  • setCachingLevel
  • cachePurgeEverything
  • cachePurge
  • deleteZone

CloudflareZoneLockdown

  • listLockdowns
  • createLockdown
  • getLockdownDetails
  • updateLockdown
  • deleteLockdown

CloudflareZoneSettings

  • getMinifySetting
  • getRocketLoaderSetting
  • getAlwaysOnlineSetting
  • getEmailObfuscationSetting
  • getServerSideExcludeSetting
  • getHotlinkProtectionSetting
  • getBrowserCacheTtlSetting
  • updateBrowserCacheTtlSetting
  • updateMinifySetting
  • updateRocketLoaderSetting
  • updateAlwaysOnlineSetting
  • updateEmailObfuscationSetting
  • updateHotlinkProtectionSetting
  • updateServerSideExcludeSetting

Usage

This library uses Dependency injection. Dependency injection is a fancy phrase that essentially means this: class dependencies are "injected" into the class via the constructor or, in some cases, "setter" methods.

use Villaflor\Cloudflare\CloudflareDNS;

class MyClass
{
    private $cloudflareDNS;

    public function __construct(CloudflareDNS $cloudflareDNS)
    {
        $this->cloudflareDNS = $cloudflareDNS;
    }

    public function UpdateDNS()
    {
        $details = [
            'type' => 'A',
            'name' => 'my-domain.com',
            'content' => '1.2.3.4',
            'ttl' => 1,
            'proxied' => true,
        ];

        return $this->cloudflareDNS->updateRecordDetails('zone-id', 'record-id', $details);
    }
    
    public function DetailDNS()
    {
        return $this->cloudflareDNS->getRecordDetails('zone-id', 'record-id');
    }
    
    public function ListDNS()
    {
        return $this->cloudflareDNS->listRecords('zone-id');
    }
}