themes !== null) { return $this->themes; } $themes = collect(); foreach ($this->roots() as $root) { if (! $this->files->isDirectory($root)) { continue; } foreach ($this->files->directories($root) as $themePath) { try { $theme = $this->fromPath($themePath); $themes->put($theme->key(), $theme); } catch (\Throwable $exception) { report($exception); } } } return $this->themes = $themes->sortKeys(); } public function find(string $key): Theme { $theme = $this->all()->get($key); if (! $theme) { throw ThemeNotFoundException::forKey($key); } return $theme; } public function fromPath(string $path): Theme { $data = $this->validator->validate($this->json->read($path), $path); return new Theme( key: $data['key'], name: $data['name'], path: rtrim($path, DIRECTORY_SEPARATOR), stylesheet: $data['stylesheet'], script: $data['script'], variables: $data['variables'], meta: $data, ); } public function flush(): void { $this->themes = null; } /** @return array */ public function roots(): array { return array_values(array_unique(array_filter([ (string) config('stylist.themes_path'), ]))); } }