@param array|ThemeInterface[] $themes

@return array|ThemeInterface[]
480382
private function hydrateThemes(array $configurations, array $themes): array
    {
        foreach ($configurations as $configuration) {
            $themeName = $configuration['name'];

            $configuration['parents'] = $this->convertParentsNamesToParentsObjects($themeName, $configuration['parents'], $themes);
            $configuration['authors'] = $this->convertAuthorsArraysToAuthorsObjects($configuration['authors']);
            $configuration['screenshots'] = $this->convertScreenshotsArraysToScreenshotsObjects($configuration['screenshots']);

            /** @var ThemeInterface $theme */
            $theme = $this->themeHydrator->hydrate($configuration, $themes[$themeName]);

            Assert::isInstanceOf($theme, ThemeInterface::class);

            $themes[$themeName] = $theme;
        }

        return $themes;
    }
230023
public function all()
    {
        $themes = [];

        if ($this->files->exists($path)) {
            $scannedThemes = $this->files->directories($path);
            foreach ($scannedThemes as $theme) {
                $themes[] = basename($theme);
            }
        }
        return new Collection($themes);
    }
593191
public function setTheme($theme)
    {
        $this->theme = [];

        foreach ((array) $theme as $path) {
            $this->theme[] = $path === 'default' ? self::$defaultCSS : $path;
        }

        return $this;
    }
493122
public function allowedThemes()
    {
        if ($themes = self::$allowed_themes) {
            return ArrayLib::valuekey($themes);
        }

        $themes = [];
        if (is_dir(THEMES_PATH)) {
            foreach (scandir(THEMES_PATH) as $theme) {
                if ($theme[0] == '.') {
                    continue;
                }
                $theme = strtok($theme, '_');
                $themes[$theme] = $theme;
            }
            ksort($themes);
        }
        return $themes;
    }
757746
public function findExistingWidgets($theme, $names)
    {
        if (! is_array($names)) {
            $names = [$names];
        }
        $select = $this->getSql()->select()
            ->from($this->getTable(self::LayoutTableAlias))
            ->columns([
                'name',
            ])
            ->where([
                'theme' => $theme,
                'name'  => $names, // = new In('name', $names)
            ]);

        $result = $this->execute($select);
        return $this->toList($result, 'name');
    }
35763
public function all() : array
    {
        if ($this->themes !== null) {
            return $this->themes;
        }

        return $this->themes = $this->load();
    }
458324
public function setTheme($theme)
    {
        if($this->theme instanceof Theme) {
            $this->assets->removeFilePath($this->theme->getRealPath());
        }

        if (is_bool($theme)) {
            $this->theme = false;
        } elseif(($moduleTheme = modules()->top()->getTheme($theme, true)) instanceof Theme) {
            $this->theme = $moduleTheme;
        } elseif(($appTheme = modules()->first()->getTheme($theme, true)) instanceof Theme) {
            $this->theme = $appTheme;
        }

        if($this->theme) {
            if ( ! defined('PATH_THEME')) {
                define('PATH_THEME', $this->theme->getRealPath());
            }

            // add theme assets directory
            $this->assets->pushFilePath($this->theme->getRealPath());

            if(is_dir($themeViewPath = $this->theme->getRealPath() . 'views' . DIRECTORY_SEPARATOR)) {

                // add theme view directory
                view()->addFilePath($this->theme->getRealPath());

                // add theme output directory
                output()->pushFilePath($themeViewPath);

                $modules = modules()->getArrayCopy();

                foreach($modules as $module) {
                    if ( ! in_array($module->getType(), ['KERNEL', 'FRAMEWORK', 'APP'])) {
                        $moduleResourcesPath = str_replace(PATH_RESOURCES, '', $module->getResourcesDir());

                        if(is_dir($themeViewPath . $moduleResourcesPath)) {
                            view()->pushFilePath($themeViewPath . $moduleResourcesPath);
                        }
                    }
                }
            }
        }
        
        return $this;
    }
263299
protected function formatCache($cached)
    {
        $themes = is_array($cached) ? $cached : json_decode($cached, true);

        $results = [];

        foreach ($themes as $theme) {
            $results[] = new Theme($theme);
        }

        return $results;
    }
475611
public function getThemeConfig($theme)
    {
        $themesConfig = $this->getThemesConfig();

        if (!empty($themesConfig[$theme])) {
            return $themesConfig[$theme];
        } elseif (!empty($themesConfig['generic'])) {
            return $themesConfig['generic'];
        }

        throw new RuntimeException(
            'No theme config found for ' . $theme
            . ' and no default theme found'
        );
    }
379868
public function themeSettingsDefaults($defaults): array
    {
        $defaultsConfig = $this->config->getSubConfig(self::DEFAULTS);
        foreach ($defaultsConfig->getArrayCopy() as $key => $value) {
            $defaults[$key] = $value;
        }

        return $defaults;
    }
62859
public function hasTheme($theme)
    {
        if (is_dir($this->getThemesDir() . $theme)) {
            return true;
        } else {
            foreach (modules() as $module) {
                if (in_array($module->getType(), ['KERNEL', 'FRAMEWORK'])) {
                    continue;
                } elseif (is_dir($module->getResourcesDir('themes') . $theme)) {
                    return true;
                }
            }
        }

        return false;
    }
448202
public function theme($theme = null)
    {
        deprecationWarning(
            'Email::theme() is deprecated. Use $email->viewBuilder()->getTheme()/setTheme() instead.'
        );

        if ($theme === null) {
            return $this->getTheme();
        }

        return $this->setTheme($theme);
    }
1181897
protected function get_list_of_themes() {
        $selectablethemes = array();

        // Get all themes installed on site.
        $themes = core_component::get_plugin_list('theme');
        ksort($themes);

        foreach ($themes as $themename => $themedir) {
            // Load the theme config.
            try {
                $theme = $this->get_theme_config($themename);
            } catch (Exception $e) {
                // Bad theme, just skip it for now.
                continue;
            }
            if ($themename !== $theme->name) {
                // Obsoleted or broken theme, just skip for now.
                continue;
            }
            if ($theme->hidefromselector) {
                // The theme doesn't want to be shown in the theme selector and as theme
                // designer mode is switched off we will respect that decision.
                continue;
            }
            $selectablethemes[] = $themename;
        }

        return $selectablethemes;
    }
1203295
protected function processPattern(array $patterns)/*# : array */
    {
        $result = [];
        foreach ($patterns as $pat) {
            $part = explode('/', $pat);
            $addr = ip2long($part[0]);
            $mask = isset($part[1]) ? ((int) $part[1]) : 32;

            // fix
            $mask = $this->getMask($mask);
            $addr = $addr & $mask;

            $result[] = [$addr, $mask];
        }
        return $result;
    }
23978
public function theme($theme = null)
    {
        if ($theme === null) {
            return $this->_theme;
        }
        $this->_theme = $theme;

        return $this;
    }
260158
private function findTemplatesInThemes(BundleInterface $bundle, $theme)
    {
        $templates = $this->findTemplatesInFolder($bundle->getPath().'/Resources/themes/'.$theme);
        $name = $bundle->getName();

        foreach ($templates as $i => $template) {
            $templates[$i] = $template->set('bundle', $name);
        }

        return $templates;
    }
1139525
private function getThemeDirs(ContainerBuilder $container, array $themeList): array
    {
        $paths = array_map(
            static function (array $bundleMetadata): string {
                return $bundleMetadata['path'] . '/Resources/views/ngbm/themes';
            },
            // Reversing the list of bundles so bundles added at end have higher priority
            // when searching for a template
            array_reverse($container->getParameter('kernel.bundles_metadata'))
        );

        $paths = array_values(array_filter($paths, 'is_dir'));

        if ($container->hasParameter('twig.default_path')) {
            $defaultTwigDir = $container->getParameterBag()->resolveValue($container->getParameter('twig.default_path')) . '/ngbm/themes';
            if (is_dir($defaultTwigDir)) {
                array_unshift($paths, $defaultTwigDir);
            }
        }

        $appDir = $this->getAppDir($container) . '/Resources/views/ngbm/themes';
        if (is_dir($appDir)) {
            array_unshift($paths, $appDir);
        }

        $themeDirs = [];
        foreach ($paths as $path) {
            foreach ($themeList as $themeName) {
                $themeDirs[$themeName][] = $path . '/' . $themeName;
            }
        }

        return $themeDirs;
    }