FastlyCommands.php in Fastly 8.3
File
src/Commands/FastlyCommands.php
View source
<?php
namespace Drupal\fastly\Commands;
use Drupal\fastly\Api;
use Drupal\fastly\CacheTagsHash;
use Drush\Commands\DrushCommands;
class FastlyCommands extends DrushCommands {
protected $api;
protected $cacheTagsHash;
public function __construct(Api $api, CacheTagsHash $cache_tags_hash) {
$this->api = $api;
$this->cacheTagsHash = $cache_tags_hash;
}
public function purgeAll() {
if ($this->api
->purgeAll()) {
$this
->output()
->writeln("<info>Successfully purged/invalidated all site content on Fastly.</info>");
}
else {
$this
->output()
->writeln("<error>Unable to purge/invalidate all site content on Fastly.</error>");
}
}
public function purgeUrl($url = '') {
if (empty($url)) {
return;
}
if ($this->api
->purgeUrl($url)) {
$this
->output()
->writeln("<info>Successfully purged url on Fastly.</info>");
}
else {
$this
->output()
->writeln("<error>Unable to purge url on Fastly.</error>");
}
}
public function purgeKeys($keys = '') {
if (empty($keys)) {
return;
}
$keys = explode(',', $keys);
$hashes = $this->cacheTagsHash
->cacheTagsToHashes($keys);
if ($this->api
->purgeKeys($hashes)) {
$this
->output()
->writeln("<info>Successfully purged key(s) on Fastly.</info>");
}
else {
$this
->output()
->writeln("<error>Unable to purged key(s) on Fastly.</error>");
}
}
public function purgeService() {
if ($this->api
->purgeAll(FALSE)) {
$this
->output()
->writeln("<info>Successfully purged whole service on Fastly.</info>");
}
else {
$this
->output()
->writeln("<error>Unable to purge whole service on Fastly.</error>");
}
}
}