diff --git a/modules/cms/classes/ThemeManager.php b/modules/cms/classes/ThemeManager.php index f8bfd1163..acdc892f8 100644 --- a/modules/cms/classes/ThemeManager.php +++ b/modules/cms/classes/ThemeManager.php @@ -2,18 +2,21 @@ namespace Cms\Classes; +use FilesystemIterator; use Illuminate\Console\View\Components\Error; use Illuminate\Console\View\Components\Info; -use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Artisan; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; use System\Classes\Extensions\ExtensionManager; use System\Classes\Extensions\ExtensionManagerInterface; use System\Classes\Extensions\Source\ExtensionSource; -use Winter\Storm\Foundation\Extension\WinterExtension; use System\Models\Parameter; use Winter\Storm\Exception\ApplicationException; +use Winter\Storm\Foundation\Extension\WinterExtension; use Winter\Storm\Packager\Composer; use Winter\Storm\Support\Facades\File; +use Winter\Storm\Support\Facades\Yaml; /** * Theme manager @@ -223,6 +226,27 @@ public function availableUpdates(WinterExtension|string|null $extension = null): return $updates; } + public function findThemesInPath(string $path): array + { + $themeFiles = []; + + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), + RecursiveIteratorIterator::SELF_FIRST + ); + + foreach ($iterator as $file) { + if ($file->isFile() && $file->getFilename() === 'theme.yaml') { + $config = Yaml::parseFile($file->getRealPath()); + if (isset($config['name'])) { + $themeFiles[$config['name']] = $file->getPathname(); + } + } + } + + return $themeFiles; + } + /** * @throws ApplicationException */