public function initAssets() { $options = $this->getOptions(); $defaultWoptions = array('combined' => true, 'leaves' => false); $woptions = array(); $am = $this->getAssetManager(); $fm = $this->getFilterManager(); $fassets = array(); if (isset($options['parser'])) { foreach ($options['parser'] as $parser) { $filters = array(); foreach ($parser['files'] as $key => $file) { $filters[$key] = array(); if (isset($file['filters'])) { foreach ($file['filters'] as $f) { if (substr($f, 0, 1) == '?') { $fn = substr($f, 1); $init = (bool) (!$parser['debug']); } else { $fn = $f; $init = true; } if ($init) { if ($fm->has($fn)) { $filters[$key][] = $fm->get($fn); } } } } } $diterator = new \RecursiveDirectoryIterator($parser['directory']); $riterator = new \RecursiveIteratorIterator($diterator, \RecursiveIteratorIterator::SELF_FIRST); foreach ($riterator as $file) { if (isset($parser['blacklist'])) { foreach ($parser['blacklist'] as $bl) { if (preg_match($bl, $file->getPathName())) { continue; } } } foreach ($parser['files'] as $key => $fopts) { $ppinfo = pathinfo($fopts['output']); if ($file->isFile() && preg_match($fopts['pattern'], $file->getFilename())) { $pinfo = pathinfo($file); $pinfo['dirname'] = str_ireplace($parser['directory'], $ppinfo['dirname'], $pinfo['dirname']); $pinfo['extension'] = $ppinfo['extension']; $fasset = new \Assetic\Asset\FileAsset($file->getPathName(), $filters[$key]); $fasset->setTargetUrl($pinfo['dirname'] . '/' . $pinfo['filename'] . '.' . $pinfo['extension']); $fassets[] = $fasset; } } } } } $f = $this->getAssetFactory(); if (isset($options['collections'])) { foreach ($options['collections'] as $name => $coll) { $woptions[$name] = isset($coll['write']) ? $coll['write'] : array(); $woptions[$name] = array_merge($defaultWoptions, $woptions[$name]); $coll['options']['name'] = str_ireplace("{APPLICATION_REVISION}", APPLICATION_REVISION, $coll['options']['name']); $asset = $f->createAsset($coll['inputs'], $coll['filters'], $coll['options']); if ($coll['cache']) { $asset = new \Assetic\Asset\AssetCache($asset, $this->getAssetCache()); } $am->set($name, $asset); } } if (isset($options['fileAssets'])) { foreach ($options['fileAssets'] as $name => $fileAsset) { $asset = new \Assetic\Asset\FileAsset($fileAsset['path']); $asset->setTargetUrl($fileAsset['targetUrl']); if (isset($fileAsset['filters'])) { foreach ($fileAsset['filters'] as $filter) { $f = $this->getFilterManager()->get($filter); $asset->ensureFilter($f); } } $am->set($name, $asset); } } $am = $this->getAssetManager(); $writer = new \Assetic\AssetWriter(APPLICATION_PATH . '/../public'); foreach ($fassets as $fasset) { if (file_exists(APPLICATION_PATH . '/../public' . '/' . $fasset->getTargetUrl())) { $amod = filemtime(APPLICATION_PATH . '/../public' . '/' . $fasset->getTargetUrl()); if ($fasset->getLastModified() <= $amod) { continue; } } $writer->writeAsset($fasset); } foreach ($am->getNames() as $name) { $asset = $am->get($name); if (file_exists(APPLICATION_PATH . '/../public' . '/' . $asset->getTargetUrl())) { $amod = filemtime(APPLICATION_PATH . '/../public' . '/' . $asset->getTargetUrl()); if ($asset->getLastModified() <= $amod) { continue; } } $writeOptions = $woptions[$name]; if ($writeOptions['combined']) { $writer->writeAsset($asset); } if ($writeOptions['leaves']) { foreach ($asset as $leaf) { $writer->writeAsset($leaf); } } } }