123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
-
-
-
- use Assetic\Factory\AssetFactory;
- use Assetic\Util\TraversableString;
-
-
- function assetic_init(AssetFactory $factory)
- {
- global $_assetic;
-
- $_assetic = new stdClass();
- $_assetic->factory = $factory;
- }
-
-
- function assetic_javascripts($inputs = array(), $filters = array(), array $options = array())
- {
- if (!isset($options['output'])) {
- $options['output'] = 'js/*.js';
- }
-
- return _assetic_urls($inputs, $filters, $options);
- }
-
-
- function assetic_stylesheets($inputs = array(), $filters = array(), array $options = array())
- {
- if (!isset($options['output'])) {
- $options['output'] = 'css/*.css';
- }
-
- return _assetic_urls($inputs, $filters, $options);
- }
-
-
- function assetic_image($input, $filters = array(), array $options = array())
- {
- if (!isset($options['output'])) {
- $options['output'] = 'images/*';
- }
-
- $urls = _assetic_urls($input, $filters, $options);
-
- return current($urls);
- }
-
-
- function _assetic_urls($inputs = array(), $filters = array(), array $options = array())
- {
- global $_assetic;
-
- if (!is_array($inputs)) {
- $inputs = array_filter(array_map('trim', explode(',', $inputs)));
- }
-
- if (!is_array($filters)) {
- $filters = array_filter(array_map('trim', explode(',', $filters)));
- }
-
- $coll = $_assetic->factory->createAsset($inputs, $filters, $options);
-
- $debug = isset($options['debug']) ? $options['debug'] : $_assetic->factory->isDebug();
- $combine = isset($options['combine']) ? $options['combine'] : !$debug;
-
- $one = $coll->getTargetPath();
- if ($combine) {
- $many = array();
- foreach ($coll as $leaf) {
- $many[] = $leaf->getTargetPath();
- }
- } else {
- $many = array($one);
- }
-
- return new TraversableString($one, $many);
- }
|