Blame view

sources/3rdparty/kriswallsmith/assetic/src/Assetic/AssetManager.php 1.97 KB
6d9380f96   Cédric Dupont   Update sources OC...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  <?php
  
  /*
   * This file is part of the Assetic package, an OpenSky project.
   *
   * (c) 2010-2014 OpenSky Project Inc
   *
   * For the full copyright and license information, please view the LICENSE
   * file that was distributed with this source code.
   */
  
  namespace Assetic;
  
  use Assetic\Asset\AssetInterface;
  
  /**
   * Manages assets.
   *
   * @author Kris Wallsmith <kris.wallsmith@gmail.com>
   */
  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();
      }
  }