32 private $fileNameResolver;
37 private $notationResolver;
42 private $deployStaticFile;
47 private $minification;
54 private $options = [];
71 NotationResolver\
Module $notationResolver,
75 $this->fileNameResolver = $fileNameResolver;
76 $this->notationResolver = $notationResolver;
77 $this->deployStaticFile = $deployStaticFile;
78 $this->minification = $minification;
92 foreach (
$files as $file) {
93 $packageFile = $package->
getFile($file->getFileId());
94 if ($packageFile && $packageFile->getOrigPackage() === $package) {
97 $deployFileName = $this->fileNameResolver->resolve($file->getFileName());
98 if ($deployFileName !== $file->getFileName()) {
99 if ($this->hasOverrides($file, $package)) {
101 $file->setArea($package->
getArea());
102 $file->setTheme($package->
getTheme());
105 $file->setPackage($package);
125 $map = $this->buildMap(
131 $currentPackageFiles = array_merge($package->getFilesByType(
'less'), $package->getFilesByType(
'css'));
133 foreach ($currentPackageFiles as $file) {
134 if ($this->inParentFiles($file->getDeployedFileName(), $parentFile->
getFileName(), $map)) {
147 private function inParentFiles(
$fileName, $parentFile, $map)
149 if (isset($map[$parentFile])) {
150 if (in_array(
$fileName, $map[$parentFile])) {
153 foreach ($map[$parentFile] as $pFile) {
154 return $this->inParentFiles(
$fileName, $pFile, $map);
169 private function buildMap($filePath, $packagePath, $contentType)
171 $content = $this->deployStaticFile->readTmpFile($filePath, $packagePath);
172 $replaceCallback =
function ($matchedContent) use ($filePath, $packagePath, $contentType) {
173 $matchedFileId = $matchedContent[
'path'];
174 if (!pathinfo($matchedContent[
'path'], PATHINFO_EXTENSION)) {
175 $matchedFileId .=
'.' . $contentType;
178 $basePath = $packagePath;
180 $basePath = pathinfo($filePath, PATHINFO_DIRNAME);
183 if (strpos($resolvedPath,
'@{baseUrl}') === 0) {
184 $resolvedMapPath = str_replace(
'@{baseUrl}',
'', $resolvedPath);
186 $resolvedMapPath = $this->normalizePath($basePath .
'/' . $resolvedPath);
188 if (!isset($this->map[$filePath])) {
189 $this->map[$filePath] = [];
191 $this->map[$filePath][] = $resolvedMapPath;
192 $this->buildMap($resolvedMapPath, $packagePath, $contentType);
206 private function normalizePath(
$path)
208 if (strpos(
$path,
'/../') ===
false) {
211 $pathParts = explode(
'/',
$path);
213 foreach ($pathParts as $pathPart) {
214 if ($pathPart ==
'.') {
217 if ($pathPart ==
'..') {
218 array_pop($realPath);
221 $realPath[] = $pathPart;
223 return implode(
'/', $realPath);
__construct(FileNameResolver $fileNameResolver, NotationResolver\Module $notationResolver, DeployStaticFile $deployStaticFile, Minification $minification)
getParentFiles($type=null)
process(Package $package, array $options)
foreach($appDirs as $dir) $files
addFileToMap(PackageFile $file)