CRM_Extension_Container_Interface) * * Note: Treat as private. This is only public to facilitate debugging. */ public $containers; /** * @var CRM_Utils_Cache_Interface|NULL * * Note: Treat as private. This is only public to facilitate debugging. */ public $cache; /** * @var string the cache key used for any data stored by this container * * Note: Treat as private. This is only public to facilitate debugging. */ public $cacheKey; /** * @var array ($key => $containerName) * * Note: Treat as private. This is only public to facilitate debugging. */ public $k2c; /** * @param array $containers array($name => CRM_Extension_Container_Interface) in order from highest priority (winners) to lowest priority (losers) * @param CRM_Utils_Cache_Interface $cache * @param string $cacheKey unique name for this container */ public function __construct($containers, CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL) { $this->containers = $containers; $this->cache = $cache; $this->cacheKey = $cacheKey; } /** * {@inheritdoc} */ public function checkRequirements() { $errors = array(); foreach ($this->containers as $container) { $errors = array_merge($errors, $container->checkRequirements()); } return $errors; } /** * {@inheritdoc} */ public function getKeys() { $k2c = $this->getKeysToContainer(); return array_keys($k2c); } /** * {@inheritdoc} */ public function getPath($key) { return $this->getContainer($key)->getPath($key); } /** * {@inheritdoc} */ public function getResUrl($key) { return $this->getContainer($key)->getResUrl($key); } /** * {@inheritdoc} */ public function refresh() { if ($this->cache) { $this->cache->delete($this->cacheKey); } foreach ($this->containers as $container) { $container->refresh(); } } /** * Get the container which defines a particular key * * @return CRM_Extension_Container_Interface * @throws CRM_Extension_Exception */ public function getContainer($key) { $k2c = $this->getKeysToContainer(); if (isset($k2c[$key]) && isset($this->containers[$k2c[$key]])) { return $this->containers[$k2c[$key]]; } else { throw new CRM_Extension_Exception_MissingException("Unknown extension: $key"); } } /** * Get a list of all keys in these containers -- and the * name of the container which defines each key. * * @return array ($key => $containerName) */ public function getKeysToContainer() { if ($this->cache) { $k2c = $this->cache->get($this->cacheKey); } if (!is_array($k2c)) { $k2c = array(); $containerNames = array_reverse(array_keys($this->containers)); foreach ($containerNames as $name) { $keys = $this->containers[$name]->getKeys(); foreach ($keys as $key) { $k2c[$key] = $name; } } if ($this->cache) { $this->cache->set($this->cacheKey, $k2c); } } return $k2c; } }