<commit_before><?php
/**
 * This file is part of the RedKiteCmsBunde Application and it is distributed
 * under the GPL LICENSE Version 2.0. To use this application you must leave
 * intact this copyright notice.
 *
 * Copyright (c) RedKite Labs <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * For extra documentation and help please visit http://www.redkite-labs.com
 *
 * @license    GPL LICENSE Version 2.0
 *
 */

namespace RedKiteLabs\RedKiteCmsBundle\Core\ActiveTheme;

use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * AlActiveTheme is the object deputated to manage the active theme
 *
 * @author RedKite Labs <<EMAIL>>
 */
class AlActiveTheme implements AlActiveThemeInterface
{
    private $container = null;
    private $activeTheme = null;
    private $bootstrapVersion = null;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    /**
     * {@inheritdoc}
     */
    public function getActiveTheme()
    {
        if (null !== $this->activeTheme) {
            return $this->activeTheme;
        }
        
        if ( ! file_exists($this->getActiveThemeFile()))
        {
            $themes = $this->container->get('red_kite_labs_theme_engine.themes');
            foreach ($themes as $theme) break;

            $this->activeTheme = $theme->getThemeName();
            $this->writeActiveTheme($this->activeTheme);

            return $this->activeTheme;
        }
        
        $this->activeTheme = trim(file_get_contents($this->getActiveThemeFile()));

        return $this->activeTheme;
    }

    /**
     * {@inheritdoc}
     */
    public function writeActiveTheme($themeName)
    {
        file_put_contents($this->getActiveThemeFile(), trim($themeName));
    }
    
    public function getThemeBootstrapVersion($themeName = null)
    {
        if (null === $themeName) {
            if (null !== $this->bootstrapVersion) {
                return $this->bootstrapVersion;
            }
            
            $themeName = $this->getActiveTheme();
        }
        
        $this->bootstrapVersion = $this->container->getParameter('red_kite_cms.bootstrap_version');
        
        $themes = $this->container->getParameter('red_kite_cms.bootstrap_themes'); 
        if (array_key_exists($themeName, $themes)) {
            
            $this->bootstrapVersion = $themes[$themeName];
        }
        
        return $this->bootstrapVersion;
    }

    /**
     * Returns the file where the active theme is saved
     *
     * @return string<commit_msg>added a control to check when the red_kite_cms.bootstrap_themes is defined<commit_after><?php
/**
 * This file is part of the RedKiteCmsBunde Application and it is distributed
 * under the GPL LICENSE Version 2.0. To use this application you must leave
 * intact this copyright notice.
 *
 * Copyright (c) RedKite Labs <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * For extra documentation and help please visit http://www.redkite-labs.com
 *
 * @license    GPL LICENSE Version 2.0
 *
 */

namespace RedKiteLabs\RedKiteCmsBundle\Core\ActiveTheme;

use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * AlActiveTheme is the object deputated to manage the active theme
 *
 * @author RedKite Labs <<EMAIL>>
 */
class AlActiveTheme implements AlActiveThemeInterface
{
    private $container = null;
    private $activeTheme = null;
    private $bootstrapVersion = null;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    /**
     * {@inheritdoc}
     */
    public function getActiveTheme()
    {
        if (null !== $this->activeTheme) {
            return $this->activeTheme;
        }
        
        if ( ! file_exists($this->getActiveThemeFile()))
        {
            $themes = $this->container->get('red_kite_labs_theme_engine.themes');
            foreach ($themes as $theme) break;

            $this->activeTheme = $theme->getThemeName();
            $this->writeActiveTheme($this->activeTheme);

            return $this->activeTheme;
        }
        
        $this->activeTheme = trim(file_get_contents($this->getActiveThemeFile()));

        return $this->activeTheme;
    }

    /**
     * {@inheritdoc}
     */
    public function writeActiveTheme($themeName)
    {
        file_put_contents($this->getActiveThemeFile(), trim($themeName));
    }
    
    public function getThemeBootstrapVersion($themeName = null)
    {
        if (null === $themeName) {
            if (null !== $this->bootstrapVersion) {
                return $this->bootstrapVersion;
            }
            
            $themeName = $this->getActiveTheme();
        }
        
        $this->bootstrapVersion = $this->container->getParameter('red_kite_cms.bootstrap_version');
        
        if ( ! $this->container->hasParameter('red_kite_cms.bootstrap_themes')){
            return $this->bootstrapVersion;
        }
        
        $themes = $this->container->getParameter('red_kite_cms.bootstrap_themes'); 
        if (array_key_exists($themeName, $themes)) {
            
            $this->bootstrapVersion = $themes[$themeName];
        }
        
        return $this->bootstrapVersion;
    }

    /**
     * Returns the file where the active theme is saved
     *
     * @return string
{'fraction_non_alphanumeric': 0.11229463802130349, 'fraction_numerical': 0.0014443040259974724, 'mean_word_length': 2.464665415884928, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5811469', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1485, 'n_words': 358}