/** * {@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; }
/** * {@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; }