@param string $themeName
@param array  $parentsNames
@param array  $existingThemes

@return ThemeInterface[]
974886
private function convertParentsNamesToParentsObjects($themeName, array $parentsNames, array $existingThemes)
    {
        return array_map(static function ($parentName) use ($themeName, $existingThemes) {
            if (!isset($existingThemes[$parentName])) {
                throw new ThemeLoadingFailedException(sprintf(
                    'Unexisting theme "%s" is required by "%s".',
                    $parentName,
                    $themeName
                ));
            }

            return $existingThemes[$parentName];
        }, $parentsNames);
    }
547062
public function add(ThemeSettings $settings, string $key = null) : ?Theme
    {
        if ($key !== null) {
            $settings->key = $key;
        }

        if ($this->has($settings->key)) {
            throw new KeyExistsException("Theme with key '{$settings->key}' already exists");
        }

        if ($settings->enabled) {
            $theme = new Theme($settings);

            if ($settings->default === true && $this->default === null) {
                $this->setDefault($theme);
            }

            if ($settings->override === true && $this->override === null) {
                $this->setOverride($theme);
            }

            $this->themes[$settings->key] = $theme;
        }

        return $theme ?? null;
    }
926347
public function add(Theme $theme)
    {
        if ($this->exists($theme->name)) {
            throw new Exceptions\themeAlreadyExists($theme);
        }
        $this->themes[] = $theme;
        return $theme;
    }
856441
public static function getAvailableThemes() {
		$path = \ROOT . \DS . 'views' . \DS . self::THEMES_FOLDER . \DS . '*';
		$dirs = \glob ( $path, GLOB_ONLYDIR | GLOB_NOSORT );
		$result = [ ];
		foreach ( $dirs as $dir ) {
			$result [] = basename ( $dir );
		}
		return $result;
	}
1079791
private function parseElementNodes($children, $parentName = null)
    {
        $result = [];

        foreach ($children as $child) {
            $prefix = $child->prefix ?: null;
            $oname  = $this->normalizeKey($child->nodeName);
            $name   = $this->prefixKey($oname, $prefix);

            if (isset($result[$name])) {
                $this->parseSetResultNodes($child, $name, $result);
                continue;
            }

            $this->parseUnsetResultNodes($child, $name, $oname, $parentName, $result, $prefix);
        }

        return $result;
    }
88618
private function iterateOverCollections($children, $userId, $parent = null, $namespace = '')
    {
        $format = ('' !== $namespace ? '%s.%s' : '%s%s');
        $collections = [];
        foreach ($children as $collectionKey => $collectionItem) {
            $key = sprintf($format, $namespace, $collectionKey);
            $collections[$key] = $this->getOrCreateCollection(
                $key,
                $collectionItem['meta_title'],
                $userId,
                $parent
            )->getId();

            if (array_key_exists('collections', $collectionItem)) {
                $childCollections = $this->iterateOverCollections(
                    $collectionItem['collections'],
                    $userId,
                    $collections[$key],
                    $key
                );
                $collections = array_merge($collections, $childCollections);
            }
        }

        return $collections;
    }
127116
public function getThemeBootstrapVersion($themeName = null)
    {
        if (null === $themeName) {
            if (null !== $this->bootstrapVersion) {
                return $this->bootstrapVersion;
            }

            $themeName = $this->getActiveThemeBackend()->getThemeName();
        }

        $this->bootstrapVersion = $this->container->getParameter('red_kite_cms.bootstrap_version');

        if ( ! $this->container->hasParameter('red_kite_labs_theme_engine.bootstrap_themes')) {
            return $this->bootstrapVersion;
        }

        $themes = $this->container->getParameter('red_kite_labs_theme_engine.bootstrap_themes');
        if (array_key_exists($themeName, $themes)) {
            $this->bootstrapVersion = $themes[$themeName];
        }

        return $this->bootstrapVersion;
    }
534958
public function Themes($ThemeName = '', $TransientKey = '') {
      $this->AddJsFile('addons.js');
      $this->SetData('Title', T('Themes'));
         
      $this->Permission('Garden.Settings.Manage');
      $this->AddSideMenu('dashboard/settings/themes');
      
      $ThemeInfo = Gdn::ThemeManager()->EnabledThemeInfo(TRUE);
      $this->SetData('EnabledThemeFolder', GetValue('Folder', $ThemeInfo));
      $this->SetData('EnabledTheme', Gdn::ThemeManager()->EnabledThemeInfo());
      $this->SetData('EnabledThemeName', GetValue('Name', $ThemeInfo, GetValue('Index', $ThemeInfo)));
      
      $Themes = Gdn::ThemeManager()->AvailableThemes();
      uasort($Themes, array('SettingsController', '_NameSort'));
      
      // Remove themes that are archived
      $Remove = array();
      foreach ($Themes as $Index => $Theme) {
         $Archived = GetValue('Archived', $Theme);
         if ($Archived)
            $Remove[] = $Index;
      }
      foreach ($Remove as $Index) {
         unset($Themes[$Index]);
      }
      $this->SetData('AvailableThemes', $Themes);
      
      if (Gdn::Session()->ValidateTransientKey($TransientKey) && $ThemeName != '') {
         try {
            $ThemeInfo = Gdn::ThemeManager()->GetThemeInfo($ThemeName);
            if ($ThemeInfo === FALSE)
               throw new Exception(sprintf(T("Could not find a theme identified by '%s'"), $ThemeName));
            
            Gdn::Session()->SetPreference(array('PreviewThemeName' => '', 'PreviewThemeFolder' => '')); // Clear out the preview
            Gdn::ThemeManager()->EnableTheme($ThemeName);
            $this->EventArguments['ThemeName'] = $ThemeName;
            $this->EventArguments['ThemeInfo'] = $ThemeInfo;
            $this->FireEvent('AfterEnableTheme');
         } catch (Exception $Ex) {
            $this->Form->AddError($Ex);
         }
         
         if ($this->Form->ErrorCount() == 0)
            Redirect('/settings/themes');

      }
      $this->Render();
   }
1111795
protected function getInheritedPrivileges(array $parents)
    {
        if (! $parents) {
            return array();
        }

        $rolePrivileges = $this->acl->getRolePrivileges();
        $inherited      = array();
        foreach ($parents as $parent) {
            if (isset($rolePrivileges[$parent])) {
                $inherited = $inherited + array_flip($rolePrivileges[$parent][\Zend_Acl::TYPE_ALLOW]);
                $inherited = $inherited +
                        array_flip($rolePrivileges[$parent][\MUtil_Acl::INHERITED][\Zend_Acl::TYPE_ALLOW]);
            }
        }
        // Sneaks in:
        unset($inherited[""]);

        return $inherited;
    }
367736
protected function resolveExtends()
    {
        $extend = [];
        foreach ($this->_targets as $name => $target) {
            if (empty($target['extend'])) {
                continue;
            }
            $parent = $target['extend'];
            if (empty($this->_targets[$parent])) {
                throw new RuntimeException("Invalid extend in '$name'. There is no '$parent' target defined.");
            }
            $extend[] = $name;
        }

        $expander = function ($target) use (&$expander, $extend) {
            $config = $this->_targets[$target];
            $parentConfig = false;

            // Recurse through parents to collect all config.
            if (in_array($target, $extend)) {
                $parentConfig = $expander($config['extend']);
            }
            if (!$parentConfig) {
                return $config;
            }
            $config['files'] = array_merge($parentConfig['files'], $config['files']);
            $config['filters'] = array_merge($parentConfig['filters'], $config['filters']);
            $config['theme'] = $parentConfig['theme'] || $config['theme'];
            return $config;
        };

        foreach ($extend as $target) {
            $this->_targets[$target] = $expander($target);
        }
    }
285988
public function getRoutsFromTheme($themeName)
    {
        if(Theme::ifExists($themeName)) {
            $routeDir = base_path('themes/' . $themeName . '/routes');
            if (is_dir($routeDir)) {
                $routeFiles = File::files($routeDir);

                //                \Route::group([
                //                    'middleware' => 'frontend', // TODO add theme middleware
                //                    'namespace' => Theme::getNamespaceOf(Theme::getActiveTheme()),
                //                ], function () use ($routeFiles) {
                //                    foreach ($routeFiles as $file) {
                //                        require_once $file;
                //                    }
                //                });
            }
        }
        return $this;
    }
1309739
public function find($themeName)
    {
        // Search for registered themes
        foreach ($this->themes as $theme) {
            if ($theme->name == $themeName) {
                return $theme;
            }

        }

        throw new Exceptions\themeNotFound($themeName);
    }
988334
public static function getChildElements(DOMElement $parent, $childName)
    {
        $listElements = $parent->getElementsByTagName($childName);
        if ($listElements->length > 0) {
            $list = [];

            for ($i = 0; $i < $listElements->length; $i++) {
                $currentItem = $listElements->item($i);

                if (!$parent->isSameNode($currentItem->parentNode)) {
                    continue;
                }

                $list[] = $currentItem;
            }

            return $list;
        }

        return [];
    }
628896
public function getRules($css, $existingRules = array())
    {
        $css = $this->doCleanup($css);
        $rulesProcessor = new RuleProcessor();
        $rules = $rulesProcessor->splitIntoSeparateRules($css);

        return $rulesProcessor->convertArrayToObjects($rules, $existingRules);
    }
553087
public function setActiveTheme($themeName = '')
    {
        Event::fire('theme.before_is_set', [$this]);

        if($themeName) {
            if(!self::ifExists($themeName)) {
                throw new \Exception($themeName . ' Theme  could not be found in file directory.');
            }
        }else{
            // return mobile theme if site is accessed from mobile or tablet
            if(settings('activateMobileTheme') && (MobileDetect::isMobile() || MobileDetect::isTablet()) ) {
                $themeName = settings('mobileActiveTheme');
            }else {
                // Theme from settings
                $themeName = settings('activeTheme');

                // Or return default theme of no theme is selected in settings
                if (!$themeName) {
                    $themeName = config('project.defaultTheme');
                }
            }
        }

        // Ensure theme exist
        if(!self::ifExists($themeName)) {
            throw new \Exception("Theme '$themeName' does not exist in Themes directory!");
        }

        self::$activeTheme = $themeName;

        $this->setConfig();

        Event::fire('theme.after_is_set', [$this]);
    }
52356
public function set($themeName)
    {
        if ($this->exists($themeName)) {
            $theme = $this->find($themeName);
        } else {
            $theme = new Theme($themeName);
        }

        $this->activeTheme = $theme;

        // Get theme view paths
        $paths = $theme->getViewPaths();

        // fall-back to default paths (set in views.php config file)
        foreach ($this->laravelViewsPath as $path) {
            if (!in_array($path, $paths)) {
                $paths[] = $path;
            }
        }

        config(['view.paths' => $paths]);

        $themeViewFinder = app('view.finder');
        $themeViewFinder->setPaths($paths);
        Event::dispatch('igaster.laravel-theme.change', $theme);
        return $theme;
    }
933962
public function get_parent_themes($theme_name)
	{
		$return = array($this->create_theme_array($theme_name));
		$theme_info = $this->load_info($theme_name);

		if ( ! empty($theme_info['parent']))
		{
			$return = array_merge($return, $this->get_parent_themes($theme_info['parent']));
		}
		elseif($theme_name !== $this->fallback['name'])
		{
			$return[] = $this->fallback;
		}

		return $return;
	}