<commit_before><?php
namespace Alchemy\Component\UI;

use Alchemy\Component\UI\Widget\WidgetInterface;
use Alchemy\Component\UI\ReaderFactory;
use Alchemy\Component\UI\Parser;

/**
 * Class Parser
 *
 * @version   1.0
 * @author    <NAME> <<EMAIL>>
 * @link      https://github.com/eriknyk/phpalchemy
 * @copyright Copyright 2012 <NAME>
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 * @package   Alchemy/Component/Routing
 */
class Engine
{
    protected $schema   = 'html';
    protected $cacheDir = './';
    protected $targetBundle = '';
    protected $metaFile = '';
    protected $mapping  = array();
    protected $readerFactory = null;
    protected $reader = null;
    protected $parser = null;

    protected $widgetsCollection = array();

    /**
     * UI\Engine Constructor
     *
     * @param string $bundle bundle name to generate a its output based in its generation script and mapping rules
     * @param Reader $reader meta file source reader
     * @param Parser $parser metafile source parser
     */
    public function __construct(ReaderFactory $readerFactory, Parser $parser)
    {
        $this->readerFactory = $readerFactory;
        $this->parser = $parser;
    }

    /**
     * Prepare all engine dependencies
     */
    public function prepare()
    {
        if (empty($this->targetBundle)) {
            throw new \RuntimeException(sprintf(
                "Runtime Error: Any Bundle was selected for ui generation."
            ));
        }

        $bundleDir = __DIR__ . DIRECTORY_SEPARATOR . 'bundle' . DIRECTORY_SEPARATOR . $this->targetBundle . DIRECTORY_SEPARATOR;

        if (!is_dir($bundleDir)) {
            throw new \Exception(sprintf("Error: Bundle '%s' does not exist!.", $this->targetBundle));
        }

        $genscriptFilename = $bundleDir . DIRECTORY_SEPARATOR . 'components.genscript';
        $mappingFilename   = $bundleDir . DIRECTORY_SEPARATOR . 'mapping.php';

        //verify if the bundle is registered
        if (! file_exists($genscriptFilename)) {
            throw new \Exception(sprintf("Error: genscript file for '%s' bundle is missing.", $this->targetBundle));
        }

        if (! file_exists($genscriptFilename)) {
            throw new \Exception(sprintf("Error: mapping file for '%s' bundle is missing.", $this->targetBundle));
        }

        if (! file_exists($this->metaFile)) {
            throw new \Exception(sprintf("Error: meta file '%' does not exist.", $this->metaFile));
        }

        $this->parser->setScriptFile($genscriptFilename);
        $this->parser->parse();
        $this->mapping = include($mappingFilename);

        // load reader from factory
        $this->reader = $this->readerFactory->load($this->metaFile);
    }

    /**
     * Sets cache directory for UI Engine
     *
     * @param string $path to store cache dir path
     */
    public static function setCacheDir($path)
    {
        self::$cacheDir = $path;
    }

    public function setTargetBundle($bundleName)
    {
        $this->targetBundle = $bundleName;
    }

    public function setMetaFile($metaFile)
    {
        $this->metaFile = $metaFile;
    }<commit_msg>litle message fix<commit_after><?php
namespace Alchemy\Component\UI;

use Alchemy\Component\UI\Widget\WidgetInterface;
use Alchemy\Component\UI\ReaderFactory;
use Alchemy\Component\UI\Parser;

/**
 * Class Parser
 *
 * @version   1.0
 * @author    <NAME> <<EMAIL>>
 * @link      https://github.com/eriknyk/phpalchemy
 * @copyright Copyright 2012 <NAME>
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 * @package   Alchemy/Component/Routing
 */
class Engine
{
    protected $schema   = 'html';
    protected $cacheDir = './';
    protected $targetBundle = '';
    protected $metaFile = '';
    protected $mapping  = array();
    protected $readerFactory = null;
    protected $reader = null;
    protected $parser = null;

    protected $widgetsCollection = array();

    /**
     * UI\Engine Constructor
     *
     * @param string $bundle bundle name to generate a its output based in its generation script and mapping rules
     * @param Reader $reader meta file source reader
     * @param Parser $parser metafile source parser
     */
    public function __construct(ReaderFactory $readerFactory, Parser $parser)
    {
        $this->readerFactory = $readerFactory;
        $this->parser = $parser;
    }

    /**
     * Prepare all engine dependencies
     */
    public function prepare()
    {
        if (empty($this->targetBundle)) {
            throw new \RuntimeException(sprintf(
                "Runtime Error: Any Bundle was selected for ui generation."
            ));
        }

        $bundleDir = __DIR__ . DIRECTORY_SEPARATOR . 'bundle' . DIRECTORY_SEPARATOR . $this->targetBundle . DIRECTORY_SEPARATOR;

        if (!is_dir($bundleDir)) {
            throw new \Exception(sprintf("Error: Bundle '%s' does not exist!.", $this->targetBundle));
        }

        $genscriptFilename = $bundleDir . DIRECTORY_SEPARATOR . 'components.genscript';
        $mappingFilename   = $bundleDir . DIRECTORY_SEPARATOR . 'mapping.php';

        //verify if the bundle is registered
        if (! file_exists($genscriptFilename)) {
            throw new \Exception(sprintf("Error: genscript file for '%s' bundle is missing.", $this->targetBundle));
        }

        if (! file_exists($genscriptFilename)) {
            throw new \Exception(sprintf("Error: mapping file for '%s' bundle is missing.", $this->targetBundle));
        }

        if (! file_exists($this->metaFile)) {
            throw new \Exception(sprintf("Error: meta file '%s' does not exist.", $this->metaFile));
        }

        $this->parser->setScriptFile($genscriptFilename);
        $this->parser->parse();
        $this->mapping = include($mappingFilename);

        // load reader from factory
        $this->reader = $this->readerFactory->load($this->metaFile);
    }

    /**
     * Sets cache directory for UI Engine
     *
     * @param string $path to store cache dir path
     */
    public static function setCacheDir($path)
    {
        self::$cacheDir = $path;
    }

    public function setTargetBundle($bundleName)
    {
        $this->targetBundle = $bundleName;
    }

    public function setMetaFile($metaFile)
    {
        $this->metaFile = $metaFile;
    }
{'fraction_non_alphanumeric': 0.12376315376158316, 'fraction_numerical': 0.0018847180775875608, 'mean_word_length': 2.5916525662718555, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 51, 'https://': 2, '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': '4836041', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1739, 'n_words': 457}