|
0
|
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 |
use Assetic\Factory\AssetFactory; |
|
|
13 |
use Assetic\Util\TraversableString; |
|
|
14 |
|
|
|
15 |
/** |
|
|
16 |
* Initializes the global Assetic object. |
|
|
17 |
* |
|
|
18 |
* @param AssetFactory $factory The asset factory |
|
|
19 |
*/ |
|
|
20 |
function assetic_init(AssetFactory $factory) |
|
|
21 |
{ |
|
|
22 |
global $_assetic; |
|
|
23 |
|
|
|
24 |
$_assetic = new stdClass(); |
|
|
25 |
$_assetic->factory = $factory; |
|
|
26 |
} |
|
|
27 |
|
|
|
28 |
/** |
|
|
29 |
* Returns an array of javascript URLs. |
|
|
30 |
* |
|
|
31 |
* @param array|string $inputs Input strings |
|
|
32 |
* @param array|string $filters Filter names |
|
|
33 |
* @param array $options An array of options |
|
|
34 |
* |
|
|
35 |
* @return array An array of javascript URLs |
|
|
36 |
*/ |
|
|
37 |
function assetic_javascripts($inputs = array(), $filters = array(), array $options = array()) |
|
|
38 |
{ |
|
|
39 |
if (!isset($options['output'])) { |
|
|
40 |
$options['output'] = 'js/*.js'; |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
return _assetic_urls($inputs, $filters, $options); |
|
|
44 |
} |
|
|
45 |
|
|
|
46 |
/** |
|
|
47 |
* Returns an array of stylesheet URLs. |
|
|
48 |
* |
|
|
49 |
* @param array|string $inputs Input strings |
|
|
50 |
* @param array|string $filters Filter names |
|
|
51 |
* @param array $options An array of options |
|
|
52 |
* |
|
|
53 |
* @return array An array of stylesheet URLs |
|
|
54 |
*/ |
|
|
55 |
function assetic_stylesheets($inputs = array(), $filters = array(), array $options = array()) |
|
|
56 |
{ |
|
|
57 |
if (!isset($options['output'])) { |
|
|
58 |
$options['output'] = 'css/*.css'; |
|
|
59 |
} |
|
|
60 |
|
|
|
61 |
return _assetic_urls($inputs, $filters, $options); |
|
|
62 |
} |
|
|
63 |
|
|
|
64 |
/** |
|
|
65 |
* Returns an image URL. |
|
|
66 |
* |
|
|
67 |
* @param string $input An input |
|
|
68 |
* @param array|string $filters Filter names |
|
|
69 |
* @param array $options An array of options |
|
|
70 |
* |
|
|
71 |
* @return string An image URL |
|
|
72 |
*/ |
|
|
73 |
function assetic_image($input, $filters = array(), array $options = array()) |
|
|
74 |
{ |
|
|
75 |
if (!isset($options['output'])) { |
|
|
76 |
$options['output'] = 'images/*'; |
|
|
77 |
} |
|
|
78 |
|
|
|
79 |
$urls = _assetic_urls($input, $filters, $options); |
|
|
80 |
|
|
|
81 |
return current($urls); |
|
|
82 |
} |
|
|
83 |
|
|
|
84 |
/** |
|
|
85 |
* Returns an array of asset urls. |
|
|
86 |
* |
|
|
87 |
* @param array|string $inputs Input strings |
|
|
88 |
* @param array|string $filters Filter names |
|
|
89 |
* @param array $options An array of options |
|
|
90 |
* |
|
|
91 |
* @return array An array of URLs |
|
|
92 |
*/ |
|
|
93 |
function _assetic_urls($inputs = array(), $filters = array(), array $options = array()) |
|
|
94 |
{ |
|
|
95 |
global $_assetic; |
|
|
96 |
|
|
|
97 |
if (!is_array($inputs)) { |
|
|
98 |
$inputs = array_filter(array_map('trim', explode(',', $inputs))); |
|
|
99 |
} |
|
|
100 |
|
|
|
101 |
if (!is_array($filters)) { |
|
|
102 |
$filters = array_filter(array_map('trim', explode(',', $filters))); |
|
|
103 |
} |
|
|
104 |
|
|
|
105 |
$coll = $_assetic->factory->createAsset($inputs, $filters, $options); |
|
|
106 |
|
|
|
107 |
$debug = isset($options['debug']) ? $options['debug'] : $_assetic->factory->isDebug(); |
|
|
108 |
$combine = isset($options['combine']) ? $options['combine'] : !$debug; |
|
|
109 |
|
|
|
110 |
$one = $coll->getTargetPath(); |
|
|
111 |
if ($combine) { |
|
|
112 |
$many = array(); |
|
|
113 |
foreach ($coll as $leaf) { |
|
|
114 |
$many[] = $leaf->getTargetPath(); |
|
|
115 |
} |
|
|
116 |
} else { |
|
|
117 |
$many = array($one); |
|
|
118 |
} |
|
|
119 |
|
|
|
120 |
return new TraversableString($one, $many); |
|
|
121 |
} |