/** * Get the final build file name for a target. * * @param AssetTarget $target The target to get a name for. * @return string */ public function buildFileName(AssetTarget $target) { $file = $target->name(); if ($target->isThemed() && $this->theme) { $file = $this->theme . '-' . $file; } return $file; }
/** * {@inheritDoc} */ public function getDependencies(AssetTarget $target) { $children = []; foreach ($target->files() as $file) { $imports = CssUtils::extractImports($file->contents()); if (empty($imports)) { continue; } $ext = $this->_settings['ext']; $extLength = strlen($ext); $deps = []; foreach ($imports as $name) { if (preg_match('/(.*)\\/\\*\\*\\/\\*$/', $name, $matches)) { $path = $this->_findFile($matches[1]); $relPathBegin = mb_strlen($path) - mb_strlen($matches[1]); $result = []; $this->_dirToArray($path, $relPathBegin, $result); $deps = array_merge($deps, $result); continue; } $pathinfo = pathinfo($name); $nameAlt = ''; if (substr($pathinfo['basename'], 0, 1) !== '_') { $name = $pathinfo['dirname'] . '/_' . $pathinfo['basename']; $nameAlt = $pathinfo['dirname'] . '/' . $pathinfo['basename']; } if ($ext !== substr($name, -$extLength)) { $name .= $ext; $nameAlt .= $ext; } $deps[] = $name; if ($nameAlt !== '') { $deps[] = $nameAlt; } } foreach ($deps as $import) { $path = $this->_findFile($import); try { $file = new Local($path); $newTarget = new AssetTarget('phony.css', [$file]); $children[] = $file; } catch (\Exception $e) { // Do nothing, we just skip missing files. // sometimes these are things like compass or bourbon // internals. $newTarget = false; } // Only recurse through non-css imports as css files are not // inlined by less/sass. if ($newTarget && $ext === substr($import, -$extLength)) { $children = array_merge($children, $this->getDependencies($newTarget)); } } } return $children; }
/** * {@inheritDoc} */ public function getDependencies(AssetTarget $target) { $children = []; $hasPrefix = property_exists($this, 'optionalDependencyPrefix') && !empty($this->optionalDependencyPrefix); foreach ($target->files() as $file) { $imports = CssUtils::extractImports($file->contents()); if (empty($imports)) { continue; } $ext = $this->_settings['ext']; $extLength = strlen($ext); $deps = []; foreach ($imports as $name) { if ('.css' === substr($name, -4)) { // skip normal css imports continue; } if ($ext !== substr($name, -$extLength)) { $name .= $ext; } $deps[] = $name; if ($hasPrefix) { $deps[] = $this->_prependPrefixToFilename($name); } } foreach ($deps as $import) { $path = $this->_findFile($import); try { $file = new Local($path); $newTarget = new AssetTarget('phony.css', [$file]); $children[] = $file; } catch (\Exception $e) { // Do nothing, we just skip missing files. // sometimes these are things like compass or bourbon // internals. $newTarget = false; } // Only recurse through non-css imports as css files are not // inlined by less/sass. if ($newTarget && $ext === substr($import, -$extLength)) { $children = array_merge($children, $this->getDependencies($newTarget)); } } } return $children; }
/** * Get the dynamic build path for an asset. * * This generates URLs that work with the development dispatcher filter. * * @param string $file The build file you want to make a url for. * @param string $base The base path to fetch a url with. * @return string Generated URL. */ protected function _getRoute(AssetTarget $file, $base) { $query = []; if ($file->isThemed()) { $query['theme'] = $this->theme; } $base = rtrim($base, '/') . '/'; $query = empty($query) ? '' : '?' . http_build_query($query); return $base . $file->name() . $query; }
/** * {@inheritDoc} */ public function getDependencies(AssetTarget $target) { $children = []; foreach ($target->files() as $file) { $contents = $file->contents(); preg_match($this->_pattern, $contents, $matches); if (empty($matches)) { continue; } if ($matches[1] === '"') { // Same directory include $path = $this->_findFile($matches[2], dirname($file->path()) . DIRECTORY_SEPARATOR); } else { // scan all paths $path = $this->_findFile($matches[2]); } $dep = new Local($path); $children[] = $dep; $newTarget = new AssetTarget('phony.js', [$dep]); $children = array_merge($children, $this->getDependencies($newTarget)); } return $children; }
/** * Get a filter collection for a specific target. * * @param MiniAsset\AssetTarget $target The target to get a filter collection for. * @param boolean $debug Indicates whether it is in debug or production mode * @return MiniAsset\Filter\FilterCollection */ public function collection(AssetTarget $target, $debug = false) { $filters = []; foreach ($target->filterNames() as $name) { $filter = $this->get($name); if ($filter === null) { throw new RuntimeException("Filter '{$name}' was not loaded/configured."); } // Clone filters so the registry is not polluted. $copy = clone $filter; $copy->settings(['target' => $target->name(), 'paths' => $target->paths()]); $filters[] = $copy; } return new FilterCollection($filters, $debug); }
/** * Append an asset to the collection. * * @param AssetTarget $target The target to append * @return void */ public function append(AssetTarget $target) { $name = $target->name(); $this->indexed[$name] = $target; $this->items[] = $name; }
public function testModifiedTimeExisting() { $target = new AssetTarget(__FILE__); $this->assertSame(filemtime(__FILE__), $target->modifiedTime()); }
/** * Get the output dir * * Used to locate outputs when determining freshness. * * @param \MiniAsset\AssetTarget $target * @return string The path */ public function outputDir(AssetTarget $target) { return $target->outputDir(); }
/** * Map an extension to a content type * * @param \MiniAsset\AssetTarget $build The build target. * @return string The mapped content type. */ protected function mapType($build) { $ext = $build->ext(); $types = ['css' => 'text/css', 'js' => 'application/javascript']; return isset($types[$ext]) ? $types[$ext] : 'application/octet-stream'; }