addPublicAsset($asset); case self::STATE_PROTECTED: return $this->addProtectedAsset($asset); case self::STATE_DELETED: return $this->addDeletedAsset($asset); default: throw new \InvalidArgumentException("Invalid state {$state}"); } } /** * Mark a file as public * * @param array $asset Asset tuple * @return bool True if the asset was added to the public set */ public function addPublicAsset($asset) { // Remove from protected / deleted lists $key = $this->getAssetKey($asset); unset($this->protected[$key]); unset($this->deleted[$key]); // Skip if already public if(isset($this->public[$key])) { return false; } unset($asset['Variant']); $this->public[$key] = $asset; return true; } /** * Record an asset as protected * * @param array $asset Asset tuple * @return bool True if the asset was added to the protected set */ public function addProtectedAsset($asset) { $key = $this->getAssetKey($asset); // Don't demote from public if (isset($this->public[$key])) { return false; } unset($this->deleted[$key]); // Skip if already protected if(isset($this->protected[$key])) { return false; } unset($asset['Variant']); $this->protected[$key] = $asset; return true; } /** * Record an asset as deleted * * @param array $asset Asset tuple * @return bool True if the asset was added to the deleted set */ public function addDeletedAsset($asset) { $key = $this->getAssetKey($asset); // Only delete if this doesn't exist in any non-deleted state if (isset($this->public[$key]) || isset($this->protected[$key])) { return false; } // Skip if already deleted if(isset($this->deleted[$key])) { return false; } unset($asset['Variant']); $this->deleted[$key] = $asset; return true; } /** * Get all public assets * * @return array */ public function getPublicAssets() { return $this->public; } /** * Get protected assets * * @return array */ public function getProtectedAssets() { return $this->protected; } /** * Get deleted assets * * @return array */ public function getDeletedAssets() { return $this->deleted; } }