Skip to content

Commit

Permalink
Add globalTags setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Devin Ellis committed Apr 2, 2019
1 parent 48f53b7 commit 7b1cc86
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function getTagCollection(): TagCollection
/* @var \ostark\upper\TagCollection $collection */
$collection = $this->get('tagCollection');
$collection->setKeyPrefix($this->getSettings()->getKeyPrefix());
$collection->setGlobalTags($this->getSettings()->getGlobalTags());

return $collection;
}
Expand Down
13 changes: 13 additions & 0 deletions src/TagCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ public function setKeyPrefix($keyPrefix)
$this->keyPrefix = $keyPrefix;
}

/**
* @param array $globalTags
*/
public function setGlobalTags($globalTags)
{
if(!is_array($globalTags)) {
$globalTags = [$globalTags];
}
foreach($globalTags as $tag) {
$this->add($tag);
}
}

/**
* Prepends tag with configured prefix.
* To prevent key collision if you use the same
Expand Down
5 changes: 5 additions & 0 deletions src/config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
// 1-8 characters, special chars get removed
'keyPrefix' => getenv('UPPER_KEY_PREFIX') ?: '',


// Optional global tags to include on every response.
// Useful if you want to clear Craft objects at once
'globalTags' => getenv('UPPER_GLOBAL_TAGS') ?: [],

// Drivers settings
'drivers' => [

Expand Down
23 changes: 23 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ class Settings extends Model
*/
public $keyPrefix = '';


/**
* Global tags
*
* @var array
*/
public $globalTags = [];

// Public Methods
// =========================================================================

Expand Down Expand Up @@ -110,6 +118,21 @@ public function getKeyPrefix()
return substr($clean, 0, 8);
}

/**
* Get global tags.
* For clearing all Craft objects at once.
*
* @return array
*/
public function getGlobalTags()
{
if (!$this->globalTags) {
return [];
}

return array_map('Inflector::slug', $this->globalTags);
}

/**
* @return array
*/
Expand Down

0 comments on commit 7b1cc86

Please sign in to comment.