villaflor / laravel-cloudflare
A Laravel client library for accessing Cloudflare APIs
1.0.0
2021-02-27 20:33 UTC
Requires
- php: ^7.3|^8.0
- cloudflare/sdk: dev-master
Requires (Dev)
- ext-json: *
- orchestra/testbench: ^6.13
README
Cloudflare library for Laravel. This library is an expansion of the official Cloudflare PHP SDK
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'); } }