|null */ private ?array $themes = null; /** * @return array */ public function all(): array { if ($this->themes === null) { $this->themes = []; foreach (config('themes.paths') as $path) { foreach (glob(rtrim($path, '/\\').'/*/theme.json') ?: [] as $file) { $manifest = ThemeManifest::fromFile($file); $this->themes[$manifest->key] = $manifest; } } } return $this->themes; } public function get(string $key): ThemeManifest { return $this->all()[$key] ?? $this->all()[config('themes.base')]; } /** * The theme followed by its ancestors, ending with the base theme. * * @return list */ public function chain(string $key): array { $chain = []; $current = $this->get($key); while (! isset($chain[$current->key])) { $chain[$current->key] = $current; if ($current->parent === null || ! isset($this->all()[$current->parent])) { break; } $current = $this->all()[$current->parent]; } $base = $this->get(config('themes.base')); $chain[$base->key] ??= $base; return array_values($chain); } /** * Colour tokens of a theme including the inherited ones (base first, the theme's own definitions win). * * @return array */ public function tokens(string $key): array { $tokens = []; foreach (array_reverse($this->chain($key)) as $theme) { $tokens = [...$tokens, ...$theme->tokens]; } return $tokens; } /** * @return array */ public function options(): array { return array_map(fn (ThemeManifest $theme): string => "{$theme->name} ({$theme->version})", $this->all()); } }