Skip to content

Commit a28eb2b

Browse files
committed
refactor: reorder detection patterns in VendorFileMapper for clarity
1 parent 5d0cc83 commit a28eb2b

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

src/Service/VendorFileMapper.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,7 @@ public function mapToThemePath(string $sourcePath, string $themePath): string
2424
$sourcePath = substr($sourcePath, strlen($rootPath) + 1);
2525
}
2626

27-
// 2. Detect "Nested Module" Pattern (Priority 1) - Works for Hyva Compat & Vendor Themes
28-
// Regex search for a segment matching Vendor_Module (e.g. Magento_Catalog).
29-
// Captures (Group 1): "Vendor_Module"
30-
if (preg_match('/([A-Z][a-zA-Z0-9]*_[A-Z][a-zA-Z0-9]*)/', $sourcePath, $matches, PREG_OFFSET_CAPTURE)) {
31-
$offset = $matches[1][1];
32-
33-
// Extract from Vendor_Module onwards (e.g. "Mollie_Payment/templates/file.phtml")
34-
$relativePath = substr($sourcePath, $offset);
35-
36-
return rtrim($themePath, '/') . '/' . ltrim($relativePath, '/');
37-
}
38-
39-
// 3. Detect "Standard Module" Pattern (Priority 2)
27+
// 2. Detect "Standard Module" Pattern (Priority 1) - Best for Local Modules & Composer Packages
4028
$modules = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);
4129
foreach ($modules as $moduleName => $path) {
4230
// Normalize module path relative to root
@@ -55,6 +43,18 @@ public function mapToThemePath(string $sourcePath, string $themePath): string
5543
}
5644
}
5745

46+
// 3. Detect "Nested Module" Pattern (Priority 2) - Works for Hyva Compat & Vendor Themes
47+
// Regex search for a segment matching Vendor_Module (e.g. Magento_Catalog).
48+
// Captures (Group 1): "Vendor_Module"
49+
if (preg_match('/([A-Z][a-zA-Z0-9]*_[A-Z][a-zA-Z0-9]*)/', $sourcePath, $matches, PREG_OFFSET_CAPTURE)) {
50+
$offset = $matches[1][1];
51+
52+
// Extract from Vendor_Module onwards (e.g. "Mollie_Payment/templates/file.phtml")
53+
$relativePath = substr($sourcePath, $offset);
54+
55+
return rtrim($themePath, '/') . '/' . ltrim($relativePath, '/');
56+
}
57+
5858
// 4. Fallback
5959
throw new RuntimeException("Could not determine target module or theme structure for file: " . $sourcePath);
6060
}

0 commit comments

Comments
 (0)