1 | <?php |
||
24 | class SassEngine implements AssetEngineInterface |
||
25 | { |
||
26 | const CACHE_FILE = 'sass_engine.cache'; |
||
27 | |||
28 | private $fileSourceMap = false; |
||
29 | private $configuration; |
||
30 | /** @var PageManager */ |
||
31 | private $pageManager; |
||
32 | private $compiler; |
||
33 | private $options = []; |
||
34 | |||
35 | 7 | public function __construct(Configuration $configuration) |
|
40 | |||
41 | 1 | public function getName() |
|
45 | |||
46 | 7 | public function getConfigurationNamespace() |
|
47 | { |
||
48 | 7 | return 'scss'; |
|
49 | } |
||
50 | |||
51 | 7 | public function getDefaultConfiguration() |
|
52 | { |
||
53 | return [ |
||
54 | 7 | 'style' => 'compressed', |
|
55 | 'sourcemap' => false, |
||
56 | ]; |
||
57 | } |
||
58 | |||
59 | 7 | public function getFolder() |
|
60 | { |
||
61 | 7 | return '_sass'; |
|
62 | } |
||
63 | |||
64 | 7 | public function getExtensions() |
|
65 | { |
||
66 | 7 | return ['scss']; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * @param string $content |
||
71 | * @param $options = [ |
||
72 | * 'pageview' => new StaticPageView() |
||
73 | * ] |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | 7 | public function parse($content, array $options = []) |
|
78 | { |
||
79 | $sourceMapOptions = [ |
||
80 | 7 | 'sourceMapBasepath' => Service::getWorkingDirectory(), |
|
81 | ]; |
||
82 | |||
83 | 7 | $this->handleThemeImports($content); |
|
84 | |||
85 | // We don't need to write the source map to a file |
||
86 | 7 | if (!$this->fileSourceMap) |
|
87 | { |
||
88 | 6 | $this->compiler->setSourceMapOptions($sourceMapOptions); |
|
89 | |||
90 | 6 | return $this->compiler->compile($content); |
|
91 | } |
||
92 | |||
93 | /** @var StaticPageView $pageView */ |
||
94 | 1 | $pageView = $options['pageview']; |
|
95 | |||
96 | // Always put our source map next to the respective CSS file |
||
97 | 1 | $sourceMapTargetPath = $this->getSourceMapTargetFile($pageView); |
|
98 | 1 | $sourceMapFilename = fs::getFilename($sourceMapTargetPath); |
|
99 | |||
100 | 1 | $sourceMapOptions = array_merge($sourceMapOptions, [ |
|
101 | 1 | 'sourceMapFilename' => $sourceMapFilename, |
|
102 | 1 | 'sourceMapURL' => $pageView->getPermalink() . '.map', |
|
103 | 1 | 'sourceMapWriteTo' => $sourceMapTargetPath, |
|
104 | ]); |
||
105 | |||
106 | 1 | $sourceMapGenerator = new SourceMapGenerator($sourceMapOptions); |
|
107 | 1 | $this->compiler->setSourceMap($sourceMapGenerator); |
|
|
|||
108 | |||
109 | 1 | $sass = $this->compiler->compile($content); |
|
110 | |||
111 | 1 | $sourceMapPageView = BasePageView::createVirtual([ |
|
112 | 1 | 'permalink' => $pageView->getPermalink() . '.map', |
|
113 | 1 | ], $sourceMapGenerator->getSourceMapContents()); |
|
114 | |||
115 | 1 | $this->pageManager->trackNewPageView($sourceMapPageView); |
|
116 | |||
117 | 1 | return $sass; |
|
118 | } |
||
119 | |||
120 | 7 | public function setOptions(array $options) |
|
121 | { |
||
122 | 7 | $this->options = $options; |
|
123 | |||
124 | 7 | $this->configureImportPath(); |
|
125 | 7 | $this->configureOutputStyle(); |
|
126 | 7 | $this->configureSourceMap(); |
|
127 | 7 | } |
|
128 | |||
129 | 1 | public function setPageManager(PageManager $pageManager) |
|
133 | |||
134 | public function loadCache(Folder $cacheDir) |
||
135 | { |
||
136 | $cachePath = $cacheDir |
||
137 | ->getFilesystemPath() |
||
138 | ->appendToPath(self::CACHE_FILE) |
||
139 | ; |
||
148 | |||
149 | 1 | public function saveCache(Folder $cacheDir) |
|
162 | |||
163 | 7 | private function configureImportPath() |
|
167 | |||
168 | 7 | private function configureOutputStyle() |
|
174 | |||
175 | 7 | private function configureSourceMap() |
|
193 | |||
194 | 1 | private function getSourceMapTargetFile(StaticPageView $pageView) |
|
201 | |||
202 | 7 | private function handleThemeImports(&$content) |
|
210 | |||
211 | public static function stringToFormatter($format) |
||
228 | } |
||
229 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: