4
* This file is part of the Assetic package, an OpenSky project.
6
* (c) 2010-2013 OpenSky Project Inc
8
* For the full copyright and license information, please view the LICENSE
9
* file that was distributed with this source code.
14
use Assetic\Asset\AssetInterface;
19
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
23
private $assets = array();
26
* Gets an asset by name.
28
* @param string $name The asset name
30
* @return AssetInterface The asset
32
* @throws \InvalidArgumentException If there is no asset by that name
34
public function get($name)
36
if (!isset($this->assets[$name])) {
37
throw new \InvalidArgumentException(sprintf('There is no "%s" asset.', $name));
40
return $this->assets[$name];
44
* Checks if the current asset manager has a certain asset.
46
* @param string $name an asset name
48
* @return Boolean True if the asset has been set, false if not
50
public function has($name)
52
return isset($this->assets[$name]);
56
* Registers an asset to the current asset manager.
58
* @param string $name The asset name
59
* @param AssetInterface $asset The asset
61
* @throws \InvalidArgumentException If the asset name is invalid
63
public function set($name, AssetInterface $asset)
65
if (!ctype_alnum(str_replace('_', '', $name))) {
66
throw new \InvalidArgumentException(sprintf('The name "%s" is invalid.', $name));
69
$this->assets[$name] = $asset;
73
* Returns an array of asset names.
75
* @return array An array of asset names
77
public function getNames()
79
return array_keys($this->assets);
85
public function clear()
87
$this->assets = array();