You are here

public function Zone::listZones in CloudFlare 8

Retrieves a listing of zones in the current CloudFlare account.

Return value

array A array of CloudFlareZones objects from the current CloudFlare account.

Throws

\CloudFlarePhpSdk\Exceptions\CloudFlareApiException Application level error returned from the API.

Overrides CloudFlareZoneInterface::listZones

File

src/Zone.php, line 176

Class

Zone
Zone methods for CloudFlare.

Namespace

Drupal\cloudflare

Code

public function listZones() {
  $this->cloudFlareComposerDependenciesCheck
    ->assert();
  $zones = [];
  $cid = 'cloudflare_zone_listing';
  try {
    if ($cached = $this->cache
      ->get($cid)) {
      return $cached->data;
    }
    else {
      $zones = $this->zoneApi
        ->listZones();

      // @todo come up with a better approach.
      $num_pages = ceil(count($zones) / ZoneApi::MAX_ITEMS_PER_PAGE);
      for ($i = 0; $i < $num_pages; $i++) {
        $this->state
          ->incrementApiRateCount();
      }
      $this->cache
        ->set($cid, $zones, time() + 60 * 5, [
        'cloudflare_zone',
      ]);
    }
  } catch (CloudFlareException $e) {
    $this->logger
      ->error($e
      ->getMessage());
    throw $e;
  }
  return $zones;
}