snapshotSet}.{$this->extensionType}.{$this->extensionName}"; } /** * {@inheritdoc} */ public function getSnapshotSet() { return $this->snapshotSet; } /** * {@inheritdoc} */ public function getExtensionType() { return $this->extensionType; } /** * {@inheritdoc} */ public function getExtensionName() { return $this->extensionName; } /** * {@inheritdoc} */ public function getItems() { return $this->items; } /** * {@inheritdoc} */ public function setItems(array $items) { $this->items = $items; return $this; } /** * {@inheritdoc} */ public function getItem($collection, $name) { if (($key = $this->getItemKey($collection, $name)) !== FALSE) { return $this->items[$key]; } return NULL; } /** * {@inheritdoc} */ public function setItem($collection, $name, array $data) { $item = [ 'collection' => $collection, 'name' => $name, 'data' => $data, ]; if (($key = $this->getItemKey($collection, $name)) !== FALSE) { $this->items[$key] = $item; } else { $this->items[] = $item; } return $this; } /** * {@inheritdoc} */ public function clearItem($collection, $name) { if (($key = $this->getItemKey($collection, $name)) !== FALSE) { unset($this->items[$key]); } return $this; } /** * {@inheritdoc} */ public function save() { $collections = array_column($this->items, 'collection'); $names = array_column($this->items, 'name'); // Sort the items by collection then by name. array_multisort($collections, SORT_ASC, $names, SORT_ASC, $this->items); parent::save(); } /** * Returns the key of a given item. * * @return int|false * The key of the item or FALSE if not found. */ protected function getItemKey($collection, $name) { $items = array_filter($this->items, function ($item) use ($collection, $name) { return ($item['collection'] === $collection) && ($item['name'] === $name); }); if ($items) { return key($items); } return FALSE; } /** * {@inheritdoc} */ public function calculateDependencies() { parent::calculateDependencies(); // Create a dependency on the extension. $this->addDependency($this->extensionType, $this->extensionName); return $this; } }