Read and parse the current theme's config.yml configuration file.

@param DirectoryInterface $themeDir
@param array              $generalConfig

@return array
11903
protected function parseTheme(DirectoryInterface $themeDir, array $generalConfig)
    {
        $themeConfig = $this->parseConfigYaml('theme.yml', $themeDir);

        /** @deprecated Deprecated since 3.0, to be removed in 4.0. (config.yml was the old filename) */
        if (empty($themeConfig)) {
            $themeConfig = $this->parseConfigYaml('config.yml', $themeDir);
        }

        if ((isset($themeConfig['templatefields'])) && (is_array($themeConfig['templatefields']))) {
            $templateContentTypes = [];

            foreach ($themeConfig['templatefields'] as $template => $templateFields) {
                $fieldsContenttype = [
                    'fields'        => $templateFields,
                    'singular_name' => 'Template Fields ' . $template,
                ];

                try {
                    $templateContentTypes[$template] = $this->parseContentType(
                        $template,
                        $fieldsContenttype,
                        $generalConfig
                    );
                } catch (InvalidArgumentException $e) {
                    $this->exceptions[] = $e->getMessage();
                }
            }

            $themeConfig['templatefields'] = $templateContentTypes;
        }

        return $themeConfig;
    }
672866
public function parse($templatesDir, $kernelDir, $themeName)
    {
        $this->templatesDir = $templatesDir;
        $this->kernelDir = $kernelDir;
        $this->themeName = $themeName;

        $directories = $this->initDirectories();

        $slotsDirectory = dirname($this->templatesDir) . '/Slots';
        $slots = $this->parseSlots($slotsDirectory);
        $finder = new Finder();
        $templateFiles = $finder->files('*.twig')->in($directories);

        $templateContents = array();
        foreach ($templateFiles as $template) {
            $templateName = basename((string) $template);
            $templateContents[$templateName]["content"] =  file_get_contents($template);

            // Generate templates only in the theme top folder
            $generate = false;
            if (strpos($template, $this->kernelDir) === false && dirname($template) == $this->templatesDir) {
                $generate = true;
            }
            $templateContents[$templateName]["generate"] = $generate;
        }

        $templates = array();
        foreach ($templateFiles as $template) {
            $templateName = basename((string) $template);
            if (! $templateContents[$templateName]["generate"]) {
                continue;
            }

            $fileContents = $templateContents[$templateName]["content"];
            $contents = $this->joinTemplates($templateContents, $fileContents);
            $templateSlots = $this->parseBlocks(implode("\n", $contents), array_keys($slots));

            $templates[] = array(
                'name' => $templateName,
                'slots' => $templateSlots,
            );
        }

        return array(
            "templates" => $templates,
            "slots" => $slots,
        );
    }
892273
public static function init_config($theme_root = null)
    {
        if (static::$setup === false) {
            $config = new Config();

            if ($theme_root === null) {
                $config_cache_path = \get_stylesheet_directory() . '/cache/config/' . \sha1(NONCE_SALT . 'theme');

                if (WP_DEBUG === false && \file_exists($config_cache_path)) {
                    $config->load_from_cache(\file_get_contents($config_cache_path));
                } else {
                    $config->add_path(\get_template_directory() . '/config');

                    if (\is_child_theme()) {
                        $config->add_path(\get_stylesheet_directory() . '/config');
                    }
                }
            }

            if ($theme_root !== null) {
                $config->add_path($theme_root . '/config');
            }

            static::$container->add_instance($config);
            static::$container->alias(Config::class, 'config');
        }
    }
1374151
public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        if (empty($config['rulesets'])) {
            unset($config['rulesets']);
        }

        // Extract slugify arguments from config
        $slugifyArguments = array_intersect_key($config, array_flip(['lowercase', 'trim', 'strip_tags', 'separator', 'regexp', 'rulesets']));

        $container->setDefinition('cocur_slugify', new Definition('Cocur\Slugify\Slugify', [$slugifyArguments]));
        $container
            ->setDefinition(
                'cocur_slugify.twig.slugify',
                new Definition(
                    'Cocur\Slugify\Bridge\Twig\SlugifyExtension',
                    [new Reference('cocur_slugify')]
                )
            )
            ->addTag('twig.extension')
            ->setPublic(false);
        $container->setAlias('slugify', 'cocur_slugify');

        // for symfony versions >= 3.3
        if (Kernel::VERSION_ID >= 30300) {
            $container->setAlias('Cocur\Slugify\SlugifyInterface', 'cocur_slugify');
        }
    }
861730
protected function parseContentTypes(array $generalConfig)
    {
        $contentTypes = [];
        $tempContentTypes = $this->parseConfigYaml('contenttypes.yml');
        foreach ($tempContentTypes as $key => $contentType) {
            try {
                $contentType = $this->parseContentType($key, $contentType, $generalConfig);
                $contentTypes[$key] = $contentType;
            } catch (InvalidArgumentException $e) {
                $this->exceptions[] = $e->getMessage();
            }
        }

        return $contentTypes;
    }
331712
protected function parseClassNames(ContainerInterface $container)
    {
        if ($container->hasDefinition(ExtendedDca::NAME)) {
            $definition = $container->getDefinition(ExtendedDca::NAME);

            if (!($definition instanceof ExtendedDca)) {
                throw new DcGeneralInvalidArgumentException(
                    \sprintf(
                        'Definition with name %s must be an instance of ExtendedDca but instance of %s encountered.',
                        ExtendedDca::NAME,
                        \get_class($definition)
                    )
                );
            }
        } else {
            $definition = new ExtendedDca();
            $container->setDefinition(ExtendedDca::NAME, $definition);
        }

        if (null === $this->getFromDca('dca_config')) {
            return;
        }

        if (null !== ($class = $this->getFromDca('dca_config/controller'))) {
            $definition->setControllerClass($class);
        }

        if (null !== ($class = $this->getFromDca('dca_config/view'))) {
            $definition->setViewClass($class);
        }
    }
1276000
public function setThemePath($generalConfig)
    {
        $themeDir = isset($generalConfig['theme']) ? '/' . $generalConfig['theme'] : '';
        $themePath = isset($generalConfig['theme_path']) ? $generalConfig['theme_path'] : '/theme';
        $themeUrl = isset($generalConfig['theme_path']) ? $generalConfig['theme_path'] : '/theme';

        // See if the user has set a theme path otherwise use the default
        if (!isset($generalConfig['theme_path'])) {
            $this->setPath('themepath', $this->getPath('themebase') . $themeDir);
            $this->setUrl('theme', $themeUrl . $themeDir . '/');
        } else {
            Deprecated::warn('Config option "theme_path"', 3.3, 'Modify the "themes" path in .bolt.yml instead.');

            $this->setPath('themepath', $this->getPath('root') . $themePath . $themeDir);
            $this->setUrl('theme', $themeUrl . $themeDir . '/');
        }
    }
26531
public static function configs()
    {
        $files = File::allFiles(base_path().'/themes');
        $result = [];
        foreach ($files as $file){
            if($file->getBasename() == "config.json") {
                $result[] = self::getConfig($file->getPath());
            }
        }
        return $result;
    }
923211
private function buildGravatarConfig(ThemeModel $theme, array $config): array
    {
        $file = FilesModel::findByPk($theme->bs_gravatar_default);

        if ($file) {
            $config['gravatar']['default'] = Environment::get('base') . $file->path;
        }

        if ($theme->bs_gravatar_size) {
            $config['gravatar']['size'] = (int) $theme->bs_gravatar_size;
        }

        return $config;
    }
533515
public function findGeneralConfiguration(): array
    {
        /** @var array[] $configurationSets */
        $configurationSets = [[]];

        $modules = $this->packageRepository->findModules();
        foreach ($modules as $module) {
            $extra = $module->getExtra();
            $this->validateGeneralConfigurationSectionInExtra($extra);
            if (!isset($extra['phplist/core']['configuration'])) {
                continue;
            }

            $configurationSets[] = $extra['phplist/core']['configuration'];
        }

        return /** @scrutinizer ignore-call */ array_replace_recursive(...$configurationSets);
    }
31801
public function load(array $files, Config $config = null)
    {
        if (is_null($config)) {
            $config = new Config();
        }

        if (!$this->isValidFileList($files)) {
            throw new \RuntimeException('Invalid config file list given. At least one config file must exist.');
        }

        foreach ($files as $file) {
            if ($this->isFileExisting($file)) {
                $config->merge(
                    $this->loadFile($file)
                );
            }
        }

        return $config;
    }
272275
private static function find_theme_config($themename, $settings, $parentscheck = true) {
        // We have to use the variable name $THEME (upper case) because that
        // is what is used in theme config.php files.

        if (!$dir = theme_config::find_theme_location($themename)) {
            return null;
        }

        $THEME = new stdClass();
        $THEME->name     = $themename;
        $THEME->dir      = $dir;
        $THEME->settings = $settings;

        global $CFG; // just in case somebody tries to use $CFG in theme config
        include("$THEME->dir/config.php");

        // verify the theme configuration is OK
        if (!is_array($THEME->parents)) {
            // parents option is mandatory now
            return null;
        } else {
            // We use $parentscheck to only check the direct parents (avoid infinite loop).
            if ($parentscheck) {
                // Find all parent theme configs.
                foreach ($THEME->parents as $parent) {
                    $parentconfig = theme_config::find_theme_config($parent, $settings, false);
                    if (empty($parentconfig)) {
                        return null;
                    }
                }
            }
        }

        return $THEME;
    }
1295491
protected function getUsableConfig(InputInterface $input)
    {
        $configLoader = new ConfigLoader();
        $configFinder = new ConfigFinder();

        /**
         * This section is just for finding the right values to work with in
         * this execution.
         *
         * $options array will have, after this block, all these values
         */
        $configPath = rtrim($input->getOption('config'), DIRECTORY_SEPARATOR);

        $configValue = $configLoader->loadConfigValues(
            $this->getCommandConfigAlias(),
            $configFinder->findConfigFile($configPath),
            $this->getCommandConfigValue($input),
            $this->getDefaultConfigValue()

        );

        if (is_null($configValue)) {
            throw new Exception("Config definition must be defined in .formatter.yml file under {$this->getCommandConfigAlias()}");
        }

        return $configValue;
    }
184381
protected function getLocalConfigArrays(IConfigSource $config)
    {
        $src = $config->getSource();

        $result = [
            $config->getAlias() => $this->convertToArray($src)
        ];

        array_walk_recursive(
            $src,
            function ($value) use (&$result) {
                if ($value instanceof IConfigSource) {
                    $result[$value->getAlias()] = $this->convertToArray($value->getSource());
                }
            }
        );

        return $result;
    }
1199327
private static function returnConfig(IConfiguration $config,$baseDir="",$userDir="",$extConfigs=[])
    {
        $config->setBaseDir($baseDir);
        $config->setUserDir($userDir);
        if(!empty($extConfigs)){
            foreach ($extConfigs as $ext){
                $config->addConfigValue($ext["section"], $ext["name"], $ext["value"]);
            }
        }
        return $config;
    }
122660
protected function loadConfiguration($name, Config $config)
    {
        $themeConfig = CompiledYamlFile::instance("themes://{$name}/{$name}" . YAML_EXT)->content();
        $config->joinDefaults("themes.{$name}", $themeConfig);
    }
254763
private function getResultList(ConfigurationInterface $moduleConfiguration)
    {
        $state = $this->stateFactory->createState();
        $enrichState = $this->stateFactory->createStateEnrichedWithDefaults($state, $moduleConfiguration);
        $result = $this->resultFactory->createResult($moduleConfiguration, $enrichState);
        $resultArray = $result->asArray();
        $iterator = new \TIterator();
        foreach ($resultArray as $article) {
            $iterator->AddItem($article);
        }

        return $iterator;
    }