Skip to content

Commit 953066b

Browse files
committed
Removed asset analyzer as not needed
1 parent 30530b0 commit 953066b

File tree

1 file changed

+36
-49
lines changed

1 file changed

+36
-49
lines changed

src/ResourceManager.php

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -105,74 +105,61 @@ public function __construct(FileManagerInterface $fileManager)
105105
}
106106

107107
/**
108-
* Create static assets.
109-
*
110-
* @param string[] $paths Collection of paths for gathering assets
111-
*
112-
* @return string[] Cached assets full paths collection
108+
* Recursively process asset
109+
* @param array $dependencies Collection of assets for compilation
113110
*/
114-
public function manage(array $paths)
111+
protected function processAsset($dependencies)
115112
{
116-
$assets = $this->fileManager->scan($paths, self::TYPES, self::$excludeFolders);
113+
foreach ($dependencies as $source => $nothing) {
114+
// Read asset content
115+
$content = $this->fileManager->read($source);
117116

118-
// Iterate all assets for analyzing
119-
$cache = [];
120-
foreach ($assets as $asset) {
121-
$cache[$asset] = $this->analyzeAsset($asset);
122-
}
123-
$cache = array_filter($cache);
117+
$extension = pathinfo($source, PATHINFO_EXTENSION);
124118

125-
// Iterate invalid assets
126-
foreach ($cache as $file => $content) {
127-
$extension = pathinfo($file, PATHINFO_EXTENSION);
119+
// Resource dependant resources
120+
$innerDependencies = [];
128121

129122
// Compile content
130123
$compiled = $content;
131-
Event::fire(self::E_COMPILE, [$file, &$extension, &$compiled]);
124+
Event::fire(self::E_COMPILE, [$source, &$extension, &$compiled, &$innerDependencies]);
132125

133-
$asset = $this->getAssetCachedPath($file);
134-
$this->fileManager->write($asset, $compiled);
135-
$this->fileManager->touch($asset, $this->fileManager->lastModified($file));
126+
// Write compiled asset
127+
$target = $this->getAssetProcessedPath($source);
128+
$this->fileManager->write($target, $compiled);
129+
$this->fileManager->touch($target, $this->fileManager->lastModified($source));
136130

137-
$this->assets[$extension][] = $asset;
131+
// Go deeper in recursion
132+
$this->processAsset($innerDependencies);
138133
}
139-
140-
return $this->assets;
141134
}
142135

143136
/**
144-
* Analyze asset.
137+
* Create static assets.
145138
*
146-
* @param string $asset Full path to asset
139+
* @param string[] $paths Collection of paths for gathering assets
147140
*
148-
* @return string Analyzed asset content
141+
* @return string[] Cached assets full paths collection
149142
*/
150-
protected function analyzeAsset($asset)
143+
public function manage(array $paths)
151144
{
152-
// Generate cached resource path with possible new extension after compiling
153-
$cachedAsset = $this->getAssetCachedPath($asset);
154-
155-
$extension = pathinfo($asset, PATHINFO_EXTENSION);
145+
// Get assets list
146+
$assets = $this->fileManager->scan($paths, self::TYPES, self::$excludeFolders);
156147

157-
// If cached assets was modified or new
158-
if (!$this->isValid($asset, $cachedAsset)) {
159-
// Read asset content
160-
$content = $this->fileManager->read($asset);
161-
162-
// Fire event for analyzing resource
163-
Event::fire(self::E_ANALYZE, [
164-
$asset,
165-
$extension,
166-
&$content
167-
]);
168-
169-
return $content;
170-
} else {
171-
// Add this resource to resource collection grouped by resource type
172-
$this->assets[$this->convertType($asset)][] = $cachedAsset;
148+
// Iterate all assets for analyzing
149+
foreach ($assets as $asset) {
150+
// Build path to processed asset
151+
$cachedAsset = $this->getAssetProcessedPath($asset);
152+
153+
// If cached assets was modified or new
154+
if (!$this->isValid($asset, $cachedAsset)) {
155+
// Recursively process asset and possible dependencies
156+
$this->processAsset([$asset => []]);
157+
// Store processed asset
158+
$this->assets[pathinfo($cachedAsset, PATHINFO_EXTENSION)][] = $cachedAsset;
159+
}
173160
}
174161

175-
return '';
162+
return $this->assets;
176163
}
177164

178165
/**
@@ -182,7 +169,7 @@ protected function analyzeAsset($asset)
182169
*
183170
* @return string Full path to cached asset
184171
*/
185-
protected function getAssetCachedPath($asset)
172+
protected function getAssetProcessedPath($asset)
186173
{
187174
// Build asset project root relative path
188175
$relativePath = str_replace(self::$projectRoot, '', $asset);

0 commit comments

Comments
 (0)