### Manage TLS Settings with Cloudflare PHP SDK Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Provides examples for enabling/disabling TLS 1.3, setting the minimum TLS version, and managing TLS client authentication. Ensure $zoneID is set. ```php enableTLS13($zoneID); // Set minimum TLS version to 1.2 $tls->changeMinimumTLSVersion($zoneID, '1.2'); // Get TLS Client Auth setting echo $tls->getTLSClientAuth($zoneID); // "on" // Enable TLS Client Authentication (mutual TLS) $tls->updateTLSClientAuth($zoneID, 'on'); // Disable TLS 1.3 $tls->disableTLS13($zoneID); ?> ``` -------------------------------- ### Manage SSL Settings with Cloudflare PHP SDK Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Shows how to get and update SSL mode, enable Always Use HTTPS, and enable Automatic HTTPS Rewrites. Requires a valid $zoneID. ```php getSSLSetting($zoneID); // "full" // Upgrade to strict mode $ssl->updateSSLSetting($zoneID, 'strict'); // Enable Always Use HTTPS $ssl->updateHTTPSRedirectSetting($zoneID, 'on'); // Enable Automatic HTTPS Rewrites $ssl->updateHTTPSRewritesSetting($zoneID, 'on'); // Check SSL verification status (optionally trigger immediate retry) $status = $ssl->getSSLVerificationStatus($zoneID, retry: false); foreach ($status->result as $pack) { echo $pack->cert_status . PHP_EOL; // "active" } // Change validation method for a certificate pack $ssl->updateSSLCertificatePackValidationMethod($zoneID, 'cert-pack-uuid', 'txt'); ?> ``` -------------------------------- ### Initialize Cloudflare API Client and Get User ID Source: https://github.com/cloudflare/cloudflare-php/blob/master/README.md This snippet shows how to authenticate with the Cloudflare API using an API key and retrieve the user's ID. Ensure you replace 'user@example.com' and 'apiKey' with your actual credentials. ```php $key = new Cloudflare\API\Auth\APIKey('user@example.com', 'apiKey'); $adapter = new Cloudflare\API\Adapter\Guzzle($key); $user = new Cloudflare\API\Endpoints\User($adapter); echo $user->getUserID(); ``` -------------------------------- ### Create, List, Get, and Revoke Origin CA Certificates Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Issue and manage Cloudflare Origin CA certificates for end-to-end HTTPS. Requires a `UserServiceKey` adapter and zone ID. ```php setHostnames(['example.com', '*.example.com']); $certConfig->setRequestType(Certificate::ORIGIN_RSA); $certConfig->setRequestedValidity(365); $certConfig->setCsr("-----BEGIN CERTIFICATE REQUEST-----\nMIICvDCC...\n-----END CERTIFICATE REQUEST-----"); $certs->createCertificate($certConfig); // List all certificates for a zone $result = $certs->listCertificates($zoneID); foreach ($result->result as $cert) { echo $cert->id . ' — expires: ' . $cert->expires_on . PHP_EOL; } // Get a specific certificate $cert = $certs->getCertificate($certID, $zoneID); echo $cert->result->certificate; // PEM-encoded certificate // Revoke a certificate $certs->revokeCertificate($certID, $zoneID); // true on success ``` -------------------------------- ### User Endpoint - Get and Update User Details Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Retrieves and updates authenticated user account details. Requires an initialized Guzzle adapter with authentication. ```php getUserID(); // "7c5dae5552338874e5053f2534d2767a" echo $user->getUserEmail(); // "user@example.com" $details = $user->getUserDetails(); echo $details->username; // "cfuser01" // Update user details $updated = $user->updateUserDetails(['first_name' => 'Jane', 'last_name' => 'Smith']); echo $updated->success ? 'Updated' : 'Failed'; ``` -------------------------------- ### Create, List, Get Health, Update, and Delete Origin Pools Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Manage account-level origin pools for load balancers. Supports defining origins, health checks, and notifications. Requires an account ID. ```php 'web-1', 'address' => '198.51.100.1', 'enabled' => true, 'weight' => 1.0], ['name' => 'web-2', 'address' => '198.51.100.2', 'enabled' => true, 'weight' => 1.0], ]); $poolConfig->setDescription('Primary web servers'); $poolConfig->setNotificationEmail('ops@example.com'); $poolConfig->setCheckRegions(['WNAM', 'ENAM']); $poolConfig->enable(); $pools->createPool($accountID, $poolConfig); // List all pools for an account $allPools = $pools->listPools($accountID); foreach ($allPools as $pool) { echo $pool->id . ' — ' . $pool->name . PHP_EOL; } // Get health status of a pool $health = $pools->getPoolHealthDetails($accountID, $poolID); echo $health->pool_id . ': ' . ($health->healthy ? 'healthy' : 'unhealthy'); // Fetch pool config as object, modify, then update $existingPool = $pools->getPoolConfiguration($accountID, $poolID); $existingPool->setDescription('Updated description'); $pools->updatePool($accountID, $poolID, $existingPool); // Delete a pool $pools->deletePool($accountID, $poolID); ``` -------------------------------- ### List and Manage Cloudflare Accounts Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Demonstrates listing accounts, adding new accounts, and managing registrar domains within an account. Requires an initialized adapter. ```php listAccounts(1, 20, 'asc'); foreach ($result->result as $account) { echo $account->id . ' — ' . $account->name . PHP_EOL; } // Add a new standard account $newAccount = $accounts->addAccount('My New Account', 'standard'); echo $newAccount->id; // List registered domains in an account $domains = $accounts->getDomains($accountID); foreach ($domains as $domain) { echo $domain->name . ' — locked: ' . ($domain->locked ? 'yes' : 'no') . PHP_EOL; } // Get details for a specific registered domain $domainDetail = $accounts->getDomainDetails($accountID, 'example.com'); // Lock / unlock a domain registrar transfer $accounts->lockDomain($accountID, 'example.com'); $accounts->unlockDomain($accountID, 'example.com'); ``` -------------------------------- ### Manage WAF Settings with Cloudflare PHP SDK Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Demonstrates listing WAF packages, rule groups, and rules, as well as updating group and rule modes. Requires $zoneID and relevant IDs. ```php getPackages($zoneID, 1, 20); foreach ($packages->result as $package) { echo $package->id . ' — ' . $package->name . PHP_EOL; } // Get details for a specific package $packageID = $packages->result[0]->id; $info = $waf->getPackageInfo($zoneID, $packageID); // List rule groups in a package $groups = $waf->getGroups($zoneID, $packageID, 1, 50); foreach ($groups->result as $group) { echo $group->id . ' — ' . $group->name . ' — mode: ' . $group->mode . PHP_EOL; } // Enable a rule group $waf->updateGroup($zoneID, $packageID, $groupID, 'on'); // List WAF rules $rules = $waf->getRules($zoneID, $packageID, 1, 100); // Update a single rule to 'block' mode $waf->updateRule($zoneID, $packageID, $ruleID, 'block'); // Get rule info $rule = $waf->getRuleInfo($zoneID, $packageID, $ruleID); echo $rule->description; ?> ``` -------------------------------- ### Build Firewall Rule Actions Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Configures the action (block, allow, challenge, log) and paused state for a firewall rule. The resulting array can be passed to Firewall::createFirewallRule(). ```php setActionBlock(); // block the request $options->setActionAllow(); // allow through $options->setActionChallenge(); // CAPTCHA challenge $options->setActionJsChallenge(); // JS challenge $options->setActionLog(); // log only (Enterprise) $options->setPaused(false); // rule is active // Pass to Firewall::createFirewallRule() $array = $options->getArray(); // ['paused' => false, 'action' => 'block'] ``` -------------------------------- ### Manage Page Rules with Cloudflare PHP SDK Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Demonstrates creating, listing, retrieving, updating, and deleting Page Rules. Ensure the $adapter and $zoneID variables are properly initialized. ```php setForwardingURL(301, 'https://example.com/new-page'); $pageRules->createPageRule($zoneID, $target, $actions, true, 1); // Create a caching rule: cache everything for 1 hour $cacheTarget = new PageRulesTargets('https://example.com/assets/*'); $cacheActions = new PageRulesActions(); $cacheActions->setCacheLevel('cache_everything'); $cacheActions->setEdgeCacheTTL(3600); $cacheActions->setBrowserCacheTTL(3600); $pageRules->createPageRule($zoneID, $cacheTarget, $cacheActions, true); // List all active page rules ordered by priority $rules = $pageRules->listPageRules($zoneID, 'active', 'priority', 'asc'); foreach ($rules as $rule) { echo $rule->id . ' — ' . $rule->status . PHP_EOL; } // Get a specific rule $rule = $pageRules->getPageRuleDetails($zoneID, $ruleID); // Partially update (PATCH) $pageRules->updatePageRule($zoneID, $ruleID, active: false); // Delete $pageRules->deletePageRule($zoneID, $ruleID); ?> ``` -------------------------------- ### Create, List, Update, and Delete Load Balancers Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Manage zone-level load balancers with different steering policies and session affinity. Requires a configured adapter and zone ID. ```php setSteeringPolicy('geo'); $config->setSessionAffinity('cookie'); $config->setSessionAffinityTtl(7200); $config->setTtl(30); $config->enableProxied(); $config->enable(); $lb->createLoadBalancer($zoneID, $config); // List load balancers $balancers = $lb->listLoadBalancers($zoneID); foreach ($balancers as $balancer) { echo $balancer->name . ' — enabled: ' . ($balancer->enabled ? 'yes' : 'no') . PHP_EOL; } // Get existing config as a LoadBalancer object for modification $lbID = $balancers[0]->id; $existingConf = $lb->getLoadBalancerConfiguration($zoneID, $lbID); $existingConf->setSteeringPolicy('random'); $lb->updateLoadBalancer($zoneID, $lbID, $existingConf); // Delete a load balancer $lb->deleteLoadBalancer($zoneID, $lbID); ``` -------------------------------- ### Build Zone Lockdown IP Allowlist Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Constructs the IP and IP range configuration for a Zone Lockdown rule. The output is an array suitable for API submission. ```php addIP('203.0.113.50'); // single IP $config->addIPRange('10.0.0.0/8'); // CIDR range $config->addIPRange('198.51.100.128/25'); $array = $config->getArray(); // [ // ['target' => 'ip', 'value' => '203.0.113.50'], // ['target' => 'ip_range', 'value' => '10.0.0.0/8'], // ['target' => 'ip_range', 'value' => '198.51.100.128/25'], // ] ``` -------------------------------- ### FirewallRuleOptions - Firewall rule action builder Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Configure the action and paused state for a Firewall Rule using a fluent interface. ```APIDOC ## FirewallRuleOptions — Firewall rule action builder Sets the action and paused state for a Firewall Rule. ```php $options = new FirewallRuleOptions(); // Available actions: $options->setActionBlock(); // block the request $options->setActionAllow(); // allow through $options->setActionChallenge(); // CAPTCHA challenge $options->setActionJsChallenge(); // JS challenge $options->setActionLog(); // log only (Enterprise) $options->setPaused(false); // rule is active // Pass to Firewall::createFirewallRule() $array = $options->getArray(); // ['paused' => false, 'action' => 'block'] ``` ``` -------------------------------- ### Guzzle Adapter Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Wraps GuzzleHTTP to make all API calls. Accepts any Auth implementation. Optionally accepts a custom base URI. Throws ResponseException on 4xx/5xx responses. ```APIDOC ## Guzzle — HTTP Adapter ### Description Wraps GuzzleHTTP to make all API calls. Accepts any `Auth` implementation. Optionally accepts a custom base URI (defaults to `https://api.cloudflare.com/client/v4/`). Throws `ResponseException` on 4xx/5xx responses with the parsed Cloudflare error message. ### Method `get(string $uri, array $options = [])` `post(string $uri, array $options = [])` `put(string $uri, array $options = [])` `delete(string $uri, array $options = [])` ### Endpoint `https://api.cloudflare.com/client/v4/` (default base URI) ### Parameters #### Constructor Parameters - **auth** (AuthInterface) - Required - An instance of an authentication provider (e.g., `APIKey`, `APIToken`). - **baseUri** (string) - Optional - A custom base URI for the API endpoint. ### Request Example ```php get('user'); $body = json_decode($response->getBody()); echo $body->result->email; // user@example.com } catch (ResponseException $e) { // $e->getMessage() returns Cloudflare's error message // $e->getCode() returns Cloudflare's error code (e.g. 9109) echo 'API error ' . $e->getCode() . ': ' . $e->getMessage(); } ``` ### Response #### Success Response (200) - **body** (Psr\Http\Message\StreamInterface) - The response body stream. #### Error Response (4xx/5xx) - **ResponseException** - An exception object containing error details. - **message** (string) - Cloudflare's structured error message. - **code** (int) - Cloudflare's error code. ``` -------------------------------- ### Manage Firewall Rules with Cloudflare PHP SDK Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Create, list, update, and delete Cloudflare Firewall Rules using Wirefilter expressions. Use FirewallRuleOptions to define actions like block or JS challenge. Ensure the adapter is initialized. ```php setActionBlock(); $firewall->createFirewallRule( $zoneID, '(ip.geoip.country eq "CN")', $options, 'Block China traffic', 1 ); // Create a JS challenge rule $jsOptions = new FirewallRuleOptions(); $jsOptions->setActionJsChallenge(); $firewall->createFirewallRule( $zoneID, '(cf.threat_score gt 14)', $jsOptions, 'Challenge high-threat IPs' ); // List rules (page 1, 50 per page) $result = $firewall->listFirewallRules($zoneID, 1, 50); foreach ($result->result as $rule) { echo $rule->id . ' — ' . $rule->action . ' — ' . $rule->filter->expression . PHP_EOL; } // Update a rule $updateOptions = new FirewallRuleOptions(); $updateOptions->setActionAllow(); $firewall->updateFirewallRule($zoneID, $ruleID, $filterID, '(ip.src eq 192.0.2.1)', $updateOptions); // Delete a rule $firewall->deleteFirewallRule($zoneID, $ruleID); // true on success ``` -------------------------------- ### Build Page Rule Actions Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Fluently configures various actions for a Page Rule, including caching, security, HTTPS, and forwarding settings. The resulting object can be used to build a Page Rule. ```php setCacheLevel('cache_everything'); $actions->setEdgeCacheTTL(86400); $actions->setBrowserCacheTTL(86400); // Security settings $actions->setSecurityLevel('high'); $actions->setWAF(true); // HTTPS settings $actions->setAlwaysUseHTTPS(true); $actions->setAutomatedHTTPSRewrites(true); // Forwarding redirect $actions->setForwardingURL(301, 'https://example.com/new-path'); // Minification $actions->setMinification(true, true, true); // HTML, CSS, JS ``` -------------------------------- ### Manage Custom Hostnames and SSL Configuration Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Add, list, update, and delete custom hostnames with SSL configuration for Cloudflare for SaaS. Supports HTTP, TXT, and email validation methods. Requires zone ID. ```php addHostname( $zoneID, 'customer.clientdomain.com', 'http', // SSL validation method: 'http', 'txt', 'email' 'dv', // SSL type: 'dv' [], // additional SSL settings 'origin.example.com' // custom origin server ); echo $result->id; echo $result->ssl->status; // 'pending_validation' // List all custom hostnames $list = $hostnames->listHostnames($zoneID, '', '', 1, 20); foreach ($list->result as $h) { echo $h->hostname . ' — ' . $h->ssl->status . PHP_EOL; } // Get a specific hostname by ID $hostnameDetail = $hostnames->getHostname($zoneID, $hostnameID); // Update SSL method $hostnames->updateHostname($zoneID, $hostnameID, 'txt'); // Get fallback origin $fallback = $hostnames->getFallbackOrigin($zoneID); echo $fallback->origin; // Delete a custom hostname $hostnames->deleteHostname($zoneID, $hostnameID); ``` -------------------------------- ### ZoneLockdown Configuration - IP allowlist builder Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Construct the IP address or CIDR range configuration for a Zone Lockdown rule. ```APIDOC ## ZoneLockdown Configuration — IP allowlist builder Builds the allowed IP/range configuration for a Zone Lockdown rule. ```php $config = new ZoneLockdownConfig(); $config->addIP('203.0.113.50'); // single IP $config->addIPRange('10.0.0.0/8'); // CIDR range $config->addIPRange('198.51.100.128/25'); $array = $config->getArray(); // [ // ['target' => 'ip', 'value' => '203.0.113.50'], // ['target' => 'ip_range', 'value' => '10.0.0.0/8'], // ['target' => 'ip_range', 'value' => '198.51.100.128/25'], // ] ``` ``` -------------------------------- ### LoadBalancer Configuration - Load balancer builder Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Construct and modify load balancer configurations using a value object. ```APIDOC ## LoadBalancer Configuration — Load balancer builder Value object for constructing and modifying load balancer configurations. ```php $config = new LoadBalancer( 'lb.example.com', ['pool-id-1', 'pool-id-2'], // default pools (priority order) 'pool-id-fallback' // fallback pool ); $config->setSteeringPolicy('geo'); // 'off', 'geo', 'random', 'dynamic_latency' $config->setSessionAffinity('cookie'); // 'none', 'cookie', 'ip_cookie' $config->setSessionAffinityTtl(3600); // 1800–604800 seconds $config->setTtl(30); $config->setDescription('Production LB'); $config->enableProxied(); $config->enable(); $config->setRegionPools(['WNAM' => ['pool-id-1'], 'ENAM' => ['pool-id-2']]); // Serialise to array for API submission $array = $config->getArray(); ``` ``` -------------------------------- ### WAF Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Lists and manages WAF packages, rule groups, and individual rules for a zone. ```APIDOC ## WAF — Web Application Firewall Lists and manages WAF packages, rule groups, and individual rules for a zone. ### Description This section details how to interact with the Web Application Firewall (WAF) API. It covers listing and retrieving information about WAF packages, rule groups, and individual rules, as well as updating the mode of rule groups and rules. ### Methods - `getPackages(zoneID, [ page ], [ perPage ])` - `getPackageInfo(zoneID, packageID)` - `getGroups(zoneID, packageID, [ page ], [ perPage ])` - `updateGroup(zoneID, packageID, groupID, mode)` - `getRules(zoneID, packageID, [ page ], [ perPage ])` - `updateRule(zoneID, packageID, ruleID, mode)` - `getRuleInfo(zoneID, packageID, ruleID)` ### Example Usage ```php use Cloudflare\API\Endpoints\WAF; $waf = new WAF($adapter); // List WAF packages $packages = $waf->getPackages($zoneID, 1, 20); foreach ($packages->result as $package) { echo $package->id . ' — ' . $package->name . PHP_EOL; } // Get details for a specific package $packageID = $packages->result[0]->id; $info = $waf->getPackageInfo($zoneID, $packageID); // List rule groups in a package $groups = $waf->getGroups($zoneID, $packageID, 1, 50); foreach ($groups->result as $group) { echo $group->id . ' — ' . $group->name . ' — mode: ' . $group->mode . PHP_EOL; } // Enable a rule group $waf->updateGroup($zoneID, $packageID, $groupID, 'on'); // List WAF rules $rules = $waf->getRules($zoneID, $packageID, 1, 100); // Update a single rule to 'block' mode $waf->updateRule($zoneID, $packageID, $ruleID, 'block'); // Get rule info $rule = $waf->getRuleInfo($zoneID, $packageID, $ruleID); echo $rule->description; ``` ``` -------------------------------- ### Manage DNS Records with Cloudflare PHP SDK Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Perform full CRUD operations for DNS records including adding, listing, retrieving details, updating, and deleting records. Supports various record types like A, MX, and SRV. Ensure the adapter is properly initialized. ```php addRecord($zoneID, 'A', 'www', '198.51.100.4', 1, true); // Add an MX record with priority $dns->addRecord($zoneID, 'MX', 'example.com', 'mail.example.com', 3600, false, '10'); // Add an SRV record using the data field $dns->addRecord($zoneID, 'SRV', '_sip._tcp', '', 0, false, '', [ 'service' => '_sip', 'proto' => '_tcp', 'name' => 'example.com', 'priority' => 10, 'weight' => 20, 'port' => 5060, 'target' => 'sip.example.com', ]); // List all A records $records = $dns->listRecords($zoneID, 'A'); foreach ($records->result as $record) { echo $record->name . ' → ' . $record->content . PHP_EOL; } // Look up record ID by type and name $recordID = $dns->getRecordID($zoneID, 'A', 'www.example.com'); // Get full record details $detail = $dns->getRecordDetails($zoneID, $recordID); echo $detail->ttl; // 1 // Update a record $dns->updateRecordDetails($zoneID, $recordID, [ 'type' => 'A', 'name' => 'www', 'content' => '203.0.113.10', 'proxied' => true, ]); // Delete a record $dns->deleteRecord($zoneID, $recordID); // true on success ``` -------------------------------- ### SSL Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Reads and updates SSL mode, HTTPS redirect, HTTPS rewrite settings, and SSL verification for a zone. ```APIDOC ## SSL — SSL/TLS settings Reads and updates SSL mode, HTTPS redirect, HTTPS rewrite settings, and SSL verification for a zone. ### Description This section covers managing SSL/TLS settings for a zone, including retrieving the current SSL mode, updating it, enabling/disabling Always Use HTTPS and Automatic HTTPS Rewrites, checking SSL verification status, and changing the validation method for certificate packs. ### Methods - `getSSLSetting(zoneID)` - `updateSSLSetting(zoneID, mode)` - `updateHTTPSRedirectSetting(zoneID, status)` - `updateHTTPSRewritesSetting(zoneID, status)` - `getSSLVerificationStatus(zoneID, [ retry ])` - `updateSSLCertificatePackValidationMethod(zoneID, certPackUUID, validationMethod)` ### Example Usage ```php use Cloudflare\API\Endpoints\SSL; $ssl = new SSL($adapter); // Get current SSL mode: 'off', 'flexible', 'full', 'strict' echo $ssl->getSSLSetting($zoneID); // "full" // Upgrade to strict mode $ssl->updateSSLSetting($zoneID, 'strict'); // Enable Always Use HTTPS $ssl->updateHTTPSRedirectSetting($zoneID, 'on'); // Enable Automatic HTTPS Rewrites $ssl->updateHTTPSRewritesSetting($zoneID, 'on'); // Check SSL verification status (optionally trigger immediate retry) $status = $ssl->getSSLVerificationStatus($zoneID, retry: false); foreach ($status->result as $pack) { echo $pack->cert_status . PHP_EOL; // "active" } // Change validation method for a certificate pack $ssl->updateSSLCertificatePackValidationMethod($zoneID, 'cert-pack-uuid', 'txt'); ``` ``` -------------------------------- ### Build Load Balancer Configuration Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Constructs and modifies load balancer configurations, including pools, steering policies, and session affinity. The configuration can be serialized to an array for API submission. ```php setSteeringPolicy('geo'); // 'off', 'geo', 'random', 'dynamic_latency' $config->setSessionAffinity('cookie'); // 'none', 'cookie', 'ip_cookie' $config->setSessionAffinityTtl(3600); // 1800–604800 seconds $config->setTtl(30); $config->setDescription('Production LB'); $config->enableProxied(); $config->enable(); $config->setRegionPools(['WNAM' => ['pool-id-1'], 'ENAM' => ['pool-id-2']]); // Serialise to array for API submission $array = $config->getArray(); ``` -------------------------------- ### APIKey Authentication - Email + Global API Key Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Authenticates using a Cloudflare account email and the Global API Key. Sets the X-Auth-Email and X-Auth-Key request headers. Requires 'vendor/autoload.php' to be included. ```php setSteeringPolicy('geo'); $config->setSessionAffinity('cookie'); $config->setSessionAffinityTtl(7200); $config->setTtl(30); $config->enableProxied(); $config->enable(); $lb->createLoadBalancer($zoneID, $config); ``` ### List load balancers ```php $balancers = $lb->listLoadBalancers($zoneID); foreach ($balancers as $balancer) { echo $balancer->name . ' — enabled: ' . ($balancer->enabled ? 'yes' : 'no') . PHP_EOL; } ``` ### Update a load balancer ```php $lbID = $balancers[0]->id; $existingConf = $lb->getLoadBalancerConfiguration($zoneID, $lbID); $existingConf->setSteeringPolicy('random'); $lb->updateLoadBalancer($zoneID, $lbID, $existingConf); ``` ### Delete a load balancer ```php $lb->deleteLoadBalancer($zoneID, $lbID); ``` ``` -------------------------------- ### TLS Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Controls TLS version settings and client authentication for a zone. ```APIDOC ## TLS — TLS settings Controls TLS version settings and client authentication for a zone. ### Description This section provides methods for managing TLS settings, including enabling/disabling TLS 1.3, setting the minimum TLS version, and managing TLS client authentication (mutual TLS). ### Methods - `enableTLS13(zoneID)` - `changeMinimumTLSVersion(zoneID, version)` - `getTLSClientAuth(zoneID)` - `updateTLSClientAuth(zoneID, status)` - `disableTLS13(zoneID)` ### Example Usage ```php use Cloudflare\API\Endpoints\TLS; $tls = new TLS($adapter); // Enable TLS 1.3 $tls->enableTLS13($zoneID); // Set minimum TLS version to 1.2 $tls->changeMinimumTLSVersion($zoneID, '1.2'); // Get TLS Client Auth setting echo $tls->getTLSClientAuth($zoneID); // "on" // Enable TLS Client Authentication (mutual TLS) $tls->updateTLSClientAuth($zoneID, 'on'); // Disable TLS 1.3 $tls->disableTLS13($zoneID); ``` ``` -------------------------------- ### Guzzle Adapter - HTTP Calls and Error Handling Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Wraps GuzzleHTTP for API calls, accepting any Auth implementation. Throws ResponseException on 4xx/5xx responses, providing parsed Cloudflare error messages. Optionally accepts a custom base URI. ```php get('user'); $body = json_decode($response->getBody()); echo $body->result->email; // user@example.com } catch (ResponseException $e) { // $e->getMessage() returns Cloudflare's error message // $e->getCode() returns Cloudflare's error code (e.g. 9109) echo 'API error ' . $e->getCode() . ': ' . $e->getMessage(); } ``` -------------------------------- ### CustomHostnames Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Manages custom hostnames and their SSL configuration for Cloudflare for SaaS platforms. ```APIDOC ## Custom Hostnames — Custom hostname (SSL for SaaS) Manages custom hostnames and their SSL configuration for Cloudflare for SaaS platforms. ### Add a custom hostname with DV SSL via HTTP validation ```php $result = $hostnames->addHostname( $zoneID, 'customer.clientdomain.com', 'http', // SSL validation method: 'http', 'txt', 'email' 'dv', // SSL type: 'dv' [], // additional SSL settings 'origin.example.com' // custom origin server ); echo $result->id; echo $result->ssl->status; // 'pending_validation' ``` ### List all custom hostnames ```php $list = $hostnames->listHostnames($zoneID, '', '', 1, 20); foreach ($list->result as $h) { echo $h->hostname . ' — ' . $h->ssl->status . PHP_EOL; } ``` ### Get a specific hostname by ID ```php $hostnameDetail = $hostnames->getHostname($zoneID, $hostnameID); ``` ### Update SSL method ```php $hostnames->updateHostname($zoneID, $hostnameID, 'txt'); ``` ### Get fallback origin ```php $fallback = $hostnames->getFallbackOrigin($zoneID); echo $fallback->origin; ``` ### Delete a custom hostname ```php $hostnames->deleteHostname($zoneID, $hostnameID); ``` ``` -------------------------------- ### Manage Zone Lockdown Rules with Cloudflare PHP SDK Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Restrict access to specific URLs to predefined IP addresses or CIDR ranges. Use ZoneLockdownConfig to add IPs and IP ranges. Ensure the adapter is initialized. ```php addIP('203.0.113.50'); $config->addIPRange('198.51.100.0/24'); $lockdown->createLockdown( $zoneID, ['https://example.com/admin*'], $config, null, 'Restrict admin to office IPs' ); // List lockdowns $result = $lockdown->listLockdowns($zoneID, 1, 20); foreach ($result->result as $item) { echo $item->id . ': ' . implode(', ', $item->urls) . PHP_EOL; } // Get details $detail = $lockdown->getLockdownDetails($zoneID, $lockdownID); // Update $newConfig = new ZoneLockdownConfig(); $newConfig->addIP('203.0.113.99'); $lockdown->updateLockdown($zoneID, $lockdownID, ['https://example.com/admin*'], $newConfig); // Delete $lockdown->deleteLockdown($zoneID, $lockdownID); ``` -------------------------------- ### Retrieve Cloudflare IP Ranges Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Fetches and displays Cloudflare's IPv4 and IPv6 IP ranges. Useful for server-side allowlisting. Requires an initialized adapter. ```php listIPs(); echo "IPv4 ranges:" . PHP_EOL; foreach ($result->ipv4_cidrs as $cidr) { echo " $cidr" . PHP_EOL; } // 103.21.244.0/22 // 103.22.200.0/22 // ... echo "IPv6 ranges:" . PHP_EOL; foreach ($result->ipv6_cidrs as $cidr) { echo " $cidr" . PHP_EOL; } ``` -------------------------------- ### Zones Endpoint Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Creates, lists, queries, purges cache for, and deletes Cloudflare zones (domains). ```APIDOC ## Zones — Zone management ### Description Creates, lists, queries, purges cache for, and deletes Cloudflare zones (domains). ### Method - `addZone(string $zoneName, bool $jumpStart = false, string $accountId): object` - `getZoneID(string $zoneName): string` - `listZones(?string $name = null, ?string $status = null, int $page = 1, int $perPage = 20): object` - `cachePurgeEverything(string $zoneId): bool` - `cachePurge(string $zoneId, array $files = [], array $tags = [], array $hosts = [], array $prefixes = [])` - `changeDevelopmentMode(string $zoneId, bool $enabled): bool` - `getAnalyticsDashboard(string $zoneId, string $since, string $until): object` - `setCachingLevel(string $zoneId, string $level): bool` - `deleteZone(string $zoneId): bool` ### Endpoint Not applicable (methods operate on zones) ### Parameters #### `addZone` Parameters - **zoneName** (string) - Required - The name of the zone (e.g., 'example.com'). - **jumpStart** (bool) - Optional - Whether to enable Jump Start (defaults to false). - **accountId** (string) - Required - The ID of the account to add the zone to. #### `listZones` Parameters - **name** (string) - Optional - Filter zones by name. - **status** (string) - Optional - Filter zones by status (e.g., 'active'). - **page** (int) - Optional - The page number for pagination (defaults to 1). - **perPage** (int) - Optional - The number of results per page (defaults to 20). #### `cachePurge` Parameters - **zoneId** (string) - Required - The ID of the zone. - **files** (array) - Optional - An array of file URLs to purge. - **tags** (array) - Optional - An array of tags to purge. - **hosts** (array) - Optional - An array of hostnames to purge. - **prefixes** (array) - Optional - An array of URL prefixes to purge. #### `getAnalyticsDashboard` Parameters - **zoneId** (string) - Required - The ID of the zone. - **since** (string) - Required - The start of the time range (e.g., '-10080' for last 7 days). - **until** (string) - Required - The end of the time range (e.g., '0'). #### `setCachingLevel` Parameters - **zoneId** (string) - Required - The ID of the zone. - **level** (string) - Required - The caching level ('aggressive', 'basic', or 'simplified'). ### Request Example ```php addZone('example.com', true, 'account-id-here'); echo $newZone->id; // "023e105f4ecef8ad9ca31a8372d0c353" // Get zone ID by name $zoneID = $zones->getZoneID('example.com'); // List zones with filters $result = $zones->listZones('example.com', 'active', 1, 20); foreach ($result->result as $zone) { echo $zone->name . ' — ' . $zone->status . PHP_EOL; } // Purge all cached files $zones->cachePurgeEverything($zoneID); // true on success // Purge specific files and tags $zones->cachePurge($zoneID, files: ['https://example.com/style.css'], tags: ['tag-1', 'tag-2'] ); // Toggle development mode $zones->changeDevelopmentMode($zoneID, true); // Get analytics dashboard (last 7 days) $analytics = $zones->getAnalyticsDashboard($zoneID, '-10080', '0'); echo $analytics->totals->requests->all; // Set caching level: 'aggressive', 'basic', or 'simplified' $zones->setCachingLevel($zoneID, 'aggressive'); // Delete a zone $zones->deleteZone($zoneID); // true on success ``` ### Response #### `addZone` Response - **result** (object) - An object containing the new zone's details, including its `id`. #### `getZoneID` Response - **result** (string) - The ID of the zone. #### `listZones` Response - **result** (array) - An array of zone objects. #### `cachePurgeEverything`, `deleteZone`, `changeDevelopmentMode`, `setCachingLevel` Response - **result** (bool) - True on success, false otherwise. #### `getAnalyticsDashboard` Response - **result** (object) - An object containing analytics data. ``` -------------------------------- ### UserServiceKey Authentication Source: https://context7.com/cloudflare/cloudflare-php/llms.txt Authenticates with a User Service Key for Origin CA certificate operations specifically. ```APIDOC ## UserServiceKey — User Service Key authentication ### Description Authenticates with a User Service Key for Origin CA certificate operations specifically. ### Method Not applicable (SDK constructor) ### Endpoint Not applicable (SDK constructor) ### Parameters #### Constructor Parameters - **serviceKey** (string) - Required - The User Service Key. ### Request Example ```php