27 '#//@magento_import(?P<reference>\s+\(reference\))?\s+[\'\"](?P<path>(?![/\\\]|\w:[/\\\])[^\"\']+)[\'\"]\s*?;#';
58 private $themeProvider;
86 $asset = $chain->getAsset();
87 $replaceCallback =
function ($matchContent) use ($asset) {
88 return $this->replace($matchContent, $asset);
90 $chain->setContent(preg_replace_callback(self::REPLACE_PATTERN, $replaceCallback, $chain->getContent()));
100 protected function replace(array $matchedContent,
LocalInterface $asset)
102 $importsContent =
'';
104 $matchedFileId = $matchedContent[
'path'];
105 $isReference = !empty($matchedContent[
'reference']);
106 $relatedAsset = $this->assetRepo->createRelated($matchedFileId, $asset);
107 $resolvedPath = $relatedAsset->getFilePath();
108 $importFiles = $this->fileSource->getFiles($this->
getTheme($relatedAsset), $resolvedPath);
110 foreach ($importFiles as $importFile) {
111 $referenceString = $isReference ?
'(reference) ' :
'';
112 $importsContent .= $importFile->getModule()
113 ?
"@import $referenceString'{$importFile->getModule()}::{$resolvedPath}';\n" 114 :
"@import $referenceString'{$matchedFileId}';\n";
116 }
catch (\LogicException $e) {
117 $this->errorHandler->processException($e);
119 return $importsContent;
132 return $this->getThemeProvider()->getThemeByFullPath(
133 $context->getAreaCode() .
'/' . $context->getThemePath()
136 return $this->design->getDesignTheme();
143 private function getThemeProvider()
145 if (
null === $this->themeProvider) {
149 return $this->themeProvider;
getTheme(LocalInterface $asset)
__construct(DesignInterface $design, CollectorInterface $fileSource, ErrorHandlerInterface $errorHandler, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\View\Design\Theme\ListInterface $themeList)
process(\Magento\Framework\View\Asset\PreProcessor\Chain $chain)