|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the Assetic package, an OpenSky project. |
|
5 * |
|
6 * (c) 2010-2011 OpenSky Project Inc |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace Assetic\Asset; |
|
13 |
|
14 use Assetic\Filter\FilterInterface; |
|
15 |
|
16 /** |
|
17 * A collection of assets loaded by glob. |
|
18 * |
|
19 * @author Kris Wallsmith <kris.wallsmith@gmail.com> |
|
20 */ |
|
21 class GlobAsset extends AssetCollection |
|
22 { |
|
23 private $globs; |
|
24 private $initialized; |
|
25 |
|
26 /** |
|
27 * Constructor. |
|
28 * |
|
29 * @param string|array $globs A single glob path or array of paths |
|
30 * @param array $filters An array of filters |
|
31 * @param string $root The root directory |
|
32 */ |
|
33 public function __construct($globs, $filters = array(), $root = null) |
|
34 { |
|
35 $this->globs = (array) $globs; |
|
36 $this->initialized = false; |
|
37 |
|
38 parent::__construct(array(), $filters, $root); |
|
39 } |
|
40 |
|
41 public function all() |
|
42 { |
|
43 if (!$this->initialized) { |
|
44 $this->initialize(); |
|
45 } |
|
46 |
|
47 return parent::all(); |
|
48 } |
|
49 |
|
50 public function load(FilterInterface $additionalFilter = null) |
|
51 { |
|
52 if (!$this->initialized) { |
|
53 $this->initialize(); |
|
54 } |
|
55 |
|
56 parent::load($additionalFilter); |
|
57 } |
|
58 |
|
59 public function dump(FilterInterface $additionalFilter = null) |
|
60 { |
|
61 if (!$this->initialized) { |
|
62 $this->initialize(); |
|
63 } |
|
64 |
|
65 return parent::dump($additionalFilter); |
|
66 } |
|
67 |
|
68 public function getLastModified() |
|
69 { |
|
70 if (!$this->initialized) { |
|
71 $this->initialize(); |
|
72 } |
|
73 |
|
74 return parent::getLastModified(); |
|
75 } |
|
76 |
|
77 public function getIterator() |
|
78 { |
|
79 if (!$this->initialized) { |
|
80 $this->initialize(); |
|
81 } |
|
82 |
|
83 return parent::getIterator(); |
|
84 } |
|
85 |
|
86 /** |
|
87 * Initializes the collection based on the glob(s) passed in. |
|
88 */ |
|
89 private function initialize() |
|
90 { |
|
91 foreach ($this->globs as $glob) { |
|
92 if (false !== $paths = glob($glob)) { |
|
93 foreach ($paths as $path) { |
|
94 $this->add(new FileAsset($path, array(), $this->getSourceRoot())); |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 $this->initialized = true; |
|
100 } |
|
101 } |