<commit_before><?php

/**
 * UI service
 * This file is part of SergSXM UI package
 *
 * @package    SergSXM UI
 * @author     SergSXM <<EMAIL>>
 * @copyright  2015 SergSXM
 */

namespace Sergsxm\UIBundle\Services;

use Sergsxm\UIBundle\Exceptions\FormException;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Yaml\Yaml as YamlParser;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;

class UIService implements CacheWarmerInterface
{
    
    private $container;
    private $cacheDir;
    private $debugTrigger;
    
    public function __construct(Container $container) 
    {
        $this->container = $container;
        $this->cacheDir = $this->container->getParameter('kernel.cache_dir').DIRECTORY_SEPARATOR.'sergsxm';
        $this->debugTrigger = $this->container->getParameter('kernel.debug');
    }

/**
 * Update cache file with list of input types
 * 
 * @return boolean Is result successfull
 */
    private function updateCache($cacheDir = null) 
    {
        if ($cacheDir == null) {
            $cacheDir = $this->cacheDir;
        }
        
        $formInputTypes = array();
        $captchaTypes = array();
        
        foreach ($this->container->get('kernel')->getBundles() as $bundle) {
            if (file_exists($bundle->getPath().DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'ui.yml')) {
                $parameters = YamlParser::parse($bundle->getPath().DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'ui.yml');
                
                if (isset($parameters['form_input_types']) && is_array($parameters['form_input_types'])) {
                    foreach ($parameters['form_input_types'] as $typeName => $typeClass) {
                        if (is_string($typeClass)) {
                            $formInputTypes[$typeName] = $typeClass;
                        }
                    }
                }
                if (isset($parameters['captcha_types']) && is_array($parameters['captcha_types'])) {
                    foreach ($parameters['captcha_types'] as $typeName => $typeClass) {
                        if (is_string($typeClass)) {
                            $captchaTypes[$typeName] = $typeClass;
                        }
                    }
                }
            }
        }
        
        if (!is_dir($cacheDir)) {
            mkdir($cacheDir);
        }
        
        $f = fopen($cacheDir.DIRECTORY_SEPARATOR.'formInputTypes.php', "w");
        fwrite($f, "<?php\r\n");<commit_msg>Change Yaml::parse call with file_get_contents<commit_after><?php

/**
 * UI service
 * This file is part of SergSXM UI package
 *
 * @package    SergSXM UI
 * @author     SergSXM <<EMAIL>>
 * @copyright  2015 SergSXM
 */

namespace Sergsxm\UIBundle\Services;

use Sergsxm\UIBundle\Exceptions\FormException;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Yaml\Yaml as YamlParser;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;

class UIService implements CacheWarmerInterface
{
    
    private $container;
    private $cacheDir;
    private $debugTrigger;
    
    public function __construct(Container $container) 
    {
        $this->container = $container;
        $this->cacheDir = $this->container->getParameter('kernel.cache_dir').DIRECTORY_SEPARATOR.'sergsxm';
        $this->debugTrigger = $this->container->getParameter('kernel.debug');
    }

/**
 * Update cache file with list of input types
 * 
 * @return boolean Is result successfull
 */
    private function updateCache($cacheDir = null) 
    {
        if ($cacheDir == null) {
            $cacheDir = $this->cacheDir;
        }
        
        $formInputTypes = array();
        $captchaTypes = array();
        
        foreach ($this->container->get('kernel')->getBundles() as $bundle) {
            if (file_exists($bundle->getPath().DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'ui.yml')) {
                $parameters = YamlParser::parse(file_get_contents($bundle->getPath().DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'ui.yml'));
                
                if (isset($parameters['form_input_types']) && is_array($parameters['form_input_types'])) {
                    foreach ($parameters['form_input_types'] as $typeName => $typeClass) {
                        if (is_string($typeClass)) {
                            $formInputTypes[$typeName] = $typeClass;
                        }
                    }
                }
                if (isset($parameters['captcha_types']) && is_array($parameters['captcha_types'])) {
                    foreach ($parameters['captcha_types'] as $typeName => $typeClass) {
                        if (is_string($typeClass)) {
                            $captchaTypes[$typeName] = $typeClass;
                        }
                    }
                }
            }
        }
        
        if (!is_dir($cacheDir)) {
            mkdir($cacheDir);
        }
        
        $f = fopen($cacheDir.DIRECTORY_SEPARATOR.'formInputTypes.php', "w");
        fwrite($f, "<?php\r\n");
{'fraction_non_alphanumeric': 0.12754514022281982, 'fraction_numerical': 0.001536688436419516, 'mean_word_length': 2.200368776889982, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1034109', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1439, 'n_words': 239}