class AssetManager

Manages assets.

@author Kris Wallsmith <kris.wallsmith@gmail.com>

Hierarchy

Expanded class hierarchy of AssetManager

3 files declare their use of AssetManager
AssetFactory.php in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Factory/AssetFactory.php
AssetReference.php in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Asset/AssetReference.php
LazyAssetManager.php in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Factory/LazyAssetManager.php

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/AssetManager.php, line 21

Namespace

Assetic
View source
class AssetManager {
  private $assets = array();

  /**
   * Gets an asset by name.
   *
   * @param string $name The asset name
   *
   * @return AssetInterface The asset
   *
   * @throws \InvalidArgumentException If there is no asset by that name
   */
  public function get($name) {
    if (!isset($this->assets[$name])) {
      throw new \InvalidArgumentException(sprintf('There is no "%s" asset.', $name));
    }
    return $this->assets[$name];
  }

  /**
   * Checks if the current asset manager has a certain asset.
   *
   * @param string $name an asset name
   *
   * @return Boolean True if the asset has been set, false if not
   */
  public function has($name) {
    return isset($this->assets[$name]);
  }

  /**
   * Registers an asset to the current asset manager.
   *
   * @param string         $name  The asset name
   * @param AssetInterface $asset The asset
   *
   * @throws \InvalidArgumentException If the asset name is invalid
   */
  public function set($name, AssetInterface $asset) {
    if (!ctype_alnum(str_replace('_', '', $name))) {
      throw new \InvalidArgumentException(sprintf('The name "%s" is invalid.', $name));
    }
    $this->assets[$name] = $asset;
  }

  /**
   * Returns an array of asset names.
   *
   * @return array An array of asset names
   */
  public function getNames() {
    return array_keys($this->assets);
  }

  /**
   * Clears all assets.
   */
  public function clear() {
    $this->assets = array();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssetManager::$assets private property
AssetManager::clear public function Clears all assets.
AssetManager::get public function Gets an asset by name. 1
AssetManager::getNames public function Returns an array of asset names. 1
AssetManager::has public function Checks if the current asset manager has a certain asset. 1
AssetManager::set public function Registers an asset to the current asset manager.