Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions library/iFixit/Matryoshka/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Scope extends Prefix {
private $scopePrefix;

public function __construct(Backend $backend, $scopeName) {
// The prefix we pass along to the Prefix() constructor is never used, so
// The prefix we pass along to the Prefix() constructor is never used, so
// it doesn't matter.
parent::__construct($backend, /* $prefix = */ null);

Expand All @@ -21,9 +21,9 @@ public function getPrefix() {
return $this->scopePrefix ?: $this->getScopePrefix();
}

public function getScopePrefix(bool $reset = false, bool $generateOnMiss = true) {
if ($this->scopePrefix === null || $reset) {
$scopeValue = $reset ? self::MISS : $this->backend->get($this->getScopeKey());
public function getScopePrefix(bool $generateOnMiss = true) {
if ($this->scopePrefix === null) {
$scopeValue = $this->backend->get($this->getScopeKey());
if ($scopeValue === self::MISS) {
if ($generateOnMiss) {
$scopeValue = substr(md5(microtime() . $this->scopeName), 0, 16);
Expand All @@ -47,10 +47,12 @@ public function getScopeName() {
* this scope.
*/
public function deleteScope(): bool {
// Delete the scope by setting a new value for it.
$prefix = $this->getScopePrefix($reset = true);
// Explicitly delete the scope key from the backend to ensure that it is
// removed.
$this->backend->delete($this->getScopeKey());
$this->scopePrefix = null;

return $prefix !== self::MISS;
return true;
}

private function getScopeKey() {
Expand Down
Loading