14 use Psr\Log\LoggerInterface;
37 private $localeResolver;
44 private $deployStaticFile;
65 private $errorsCount = 0;
77 LocaleResolver $localeResolver,
79 LoggerInterface $logger
81 $this->appState = $appState;
82 $this->localeResolver = $localeResolver;
83 $this->deployStaticFile = $deployStaticFile;
97 $result = $this->appState->emulateAreaCode(
99 function () use ($package,
$options, $skipLogging) {
101 $this->localeResolver->setLocale($package->
getLocale());
102 $this->deployEmulated($package,
$options, $skipLogging);
115 public function deployEmulated(
Package $package, array
$options, $skipLogging =
false)
118 $this->errorsCount = 0;
119 $this->
register($package,
null, $skipLogging);
122 foreach ($package->
getFiles() as $file) {
123 $fileId = $file->getDeployedFileId();
125 $this->
register($package, $file, $skipLogging);
126 if ($this->checkFileSkip($fileId,
$options)) {
131 $this->processFile($file, $package);
132 }
catch (ContentProcessorException $exception) {
133 $errorMessage =
__(
'Compilation from source: ')
134 . $file->getSourcePath()
135 . PHP_EOL . $exception->getMessage();
136 $this->errorsCount++;
137 $this->logger->critical($errorMessage);
138 }
catch (\Exception $exception) {
139 $this->logger->critical($exception->getTraceAsString());
140 $this->errorsCount++;
161 private function processFile(PackageFile $file, Package $package)
163 if ($file->getContent()) {
164 $this->deployStaticFile->writeFile(
165 $file->getDeployedFileName(),
170 $parentPackage = $package->getParent();
171 if ($this->checkIfCanCopy($file, $package, $parentPackage)) {
172 $this->deployStaticFile->copyFile(
173 $file->getDeployedFileId(),
174 $parentPackage->getPath(),
178 $this->deployStaticFile->deployFile(
179 $file->getFileName(),
181 'area' => $package->getArea(),
182 'theme' => $package->getTheme(),
183 'locale' => $package->getLocale(),
184 'module' => $file->getModule(),
199 private function checkIfCanCopy(PackageFile $file, Package $package, Package $parentPackage =
null)
201 return $parentPackage
202 && $file->getOrigPackage() !== $package
204 $file->getArea() !== $package->getArea()
205 || $file->getTheme() !== $package->getTheme()
206 || $file->getLocale() !== $package->getLocale()
208 && $file->getOrigPackage() === $parentPackage
209 && $this->deployStaticFile->readFile($file->getDeployedFileId(), $parentPackage->getPath());
219 private function checkFileSkip($filePath, array
$options)
221 if ($filePath !==
'.') {
222 $ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
223 $basename = pathinfo($filePath, PATHINFO_BASENAME);
224 if ($ext ===
'less' && strpos($basename,
'_') === 0) {
243 private function register(Package $package, PackageFile $file =
null, $skipLogging =
false)
247 $logMessage =
"Processing file '{$file->getSourcePath()}'";
248 if ($file->getArea()) {
249 $logMessage .=
" for area '{$file->getArea()}'";
251 if ($file->getTheme()) {
252 $logMessage .=
", theme '{$file->getTheme()}'";
254 if ($file->getLocale()) {
255 $logMessage .=
", locale '{$file->getLocale()}'";
257 if ($file->getModule()) {
258 $logMessage .=
"module '{$file->getModule()}'";
263 'count' => $this->count,
264 'last' => $file ? $file->getSourcePath() :
'' 266 $this->deployStaticFile->writeTmpFile(
'info.json', $package->getPath(), json_encode(
$info));
269 $this->logger->info($logMessage);
deploy(Package $package, array $options, $skipLogging=false)
__construct(AppState $appState, LocaleResolver $localeResolver, DeployStaticFile $deployStaticFile, LoggerInterface $logger)
foreach( $_productCollection as $_product)() ?>" class $info