public function handle() { // first verify if a single resource file without filter was requested if (count($this->meta) == 1 && empty($this->meta[0][1]) && strstr($this->meta[0][0], $this->baseDir) === false) { $this->path = $this->locateFile($this->meta[0][0]); $this->genFilename = $this->meta[0][0]; $this->checksum = filemtime($this->path); if ($this->forceReset) { $this->meta = array(); } return true; } // continue processing multiples resources or a single filtered res. $checksum = array(); $id = array(); $this->cacheInfoFile = $this->cacheDir . '.webassets.cacheinf'; foreach ($this->meta as $i => $assetInfo) { $filename = $this->meta[$i][0] = $this->locateFile($assetInfo[0]); $checksum[] = md5_file($filename); $id[] = $assetInfo[0]; } $this->id = count($id) == 1 ? $id[0] : md5(implode(' ', $id)); if (count($checksum) == 1) { $this->checksum = $checksum[0]; $this->genFilename = basename($filename); } else { $this->checksum = md5(implode('-', $checksum)); $this->genFilename = 'x-gen-' . md5($this->checksum) . '.' . pathinfo($filename, PATHINFO_EXTENSION); } $this->loadCache(); if ($this->isCached() && !$this->isCacheOutdated()) { $this->fromCache = true; $this->path = $this->cacheInfo[$this->id]['filename']; return true; } $this->saveCacheInf(); // build asset compiled file. foreach ($this->meta as $item) { $asset = new Asset($item[0], $item[1]); $this->output .= "/*! -- File: '" . $asset->getFilename() . "' -- */\n"; $this->output .= $asset->getOutput() . "\n"; } // save generated file $this->path = $this->outputDir . $this->genFilename; if (@file_put_contents($this->path, $this->output) === false) { throw new \RuntimeException(sprintf("Runtime Error: WebAssets couldn't save generated file in '%s' directory.", $this->outputDir)); } if ($this->forceReset) { $this->meta = array(); } }
/** * @covers Asset::getFilename * @depends testConstructorWithCss */ public function testGetFilename(Asset $asset) { $this->assertEquals('styles.css', $asset->getFilename()); }