Blame view

sources/3rdparty/kriswallsmith/assetic/src/Assetic/Asset/GlobAsset.php 2.59 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  <?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\Asset;
  
  use Assetic\Filter\FilterInterface;
  use Assetic\Util\VarUtils;
  
  /**
   * A collection of assets loaded by glob.
   *
   * @author Kris Wallsmith <kris.wallsmith@gmail.com>
   */
  class GlobAsset extends AssetCollection
  {
      private $globs;
      private $initialized;
  
      /**
       * Constructor.
       *
       * @param string|array $globs   A single glob path or array of paths
       * @param array        $filters An array of filters
       * @param string       $root    The root directory
       * @param array        $vars
       */
      public function __construct($globs, $filters = array(), $root = null, array $vars = array())
      {
          $this->globs = (array) $globs;
          $this->initialized = false;
  
          parent::__construct(array(), $filters, $root, $vars);
      }
  
      public function all()
      {
          if (!$this->initialized) {
              $this->initialize();
          }
  
          return parent::all();
      }
  
      public function load(FilterInterface $additionalFilter = null)
      {
          if (!$this->initialized) {
              $this->initialize();
          }
  
          parent::load($additionalFilter);
      }
  
      public function dump(FilterInterface $additionalFilter = null)
      {
          if (!$this->initialized) {
              $this->initialize();
          }
  
          return parent::dump($additionalFilter);
      }
  
      public function getLastModified()
      {
          if (!$this->initialized) {
              $this->initialize();
          }
  
          return parent::getLastModified();
      }
  
      public function getIterator()
      {
          if (!$this->initialized) {
              $this->initialize();
          }
  
          return parent::getIterator();
      }
  
      public function setValues(array $values)
      {
          parent::setValues($values);
          $this->initialized = false;
      }
  
      /**
       * Initializes the collection based on the glob(s) passed in.
       */
      private function initialize()
      {
          foreach ($this->globs as $glob) {
              $glob = VarUtils::resolve($glob, $this->getVars(), $this->getValues());
  
              if (false !== $paths = glob($glob)) {
                  foreach ($paths as $path) {
                      if (is_file($path)) {
                          $this->add(new FileAsset($path, array(), $this->getSourceRoot()));
                      }
                  }
              }
          }
  
          $this->initialized = true;
      }
  }