<commit_before><?php
/**
 * Automation tool mixed with code generator for easier continuous development
 *
 * @link      https://github.com/hiqdev/hidev
 * @package   hidev
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
 */

namespace hidev\base;

use hidev\components\Request;
use hidev\helpers\ConfigPlugin;
use hidev\helpers\FileHelper;
use Symfony\Component\Yaml\Yaml;
use Yii;
use yii\base\InvalidParamException;
use yii\helpers\ArrayHelper;

/**
 * Application starter.
 * Chdirs to the project's root directory and loads dependencies and configs.
 *
 * XXX it's important to distinguish:
 * - goals definitions (hidev config)
 * - application config
 */
class Starter
{
    /**
     * @var string absolute path to the project root directory
     */
    private $_rootDir;

    /**
     * @var array goals definitions
     */
    private $goals = [];

    private $hidevFiles = [];

    /**
     * @var array application config files
     */
    private $appFiles = ['@hidev/config/basis.php'];

    /**
     * Make action.
     */
    public function __construct()
    {
        $request = new Request();
        list($route, $params) = $request->resolve();
        list($id, $subroute) = explode('/', $route, 2);
        if (in_array($id, ['init'], true)) {
            $this->noProject();
        } else {
            $this->startProject();
        }
    }

    public function noProject()
    {
    }

    public function startProject()
    {
        $this->getRootDir();
        $this->loadGoals();
        $this->addAliases();
        //  $this->addAutoloader();
        $this->requireAll();
        $this->includeAll();
        $this->moreConfig();
    }

    public function getConfig()
    {
        $config = ArrayHelper::merge($this->readConfig(), [
            'components' => $this->goals,
        ]);
        unset($config['include']);
        unset($config['components']['plugins']);

        foreach ($config['components'] as $id => $def) {
            if (empty($def['class'])) {
                unset($config['components'][$id]);
                $controllers[$id] = $def;
            }
        }
        $config = ArrayHelper::merge($config, [
            'controllerMap' => $controllers,
        ]);

        if (!empty($config['controllerMap'])) {
            foreach ($config['controllerMap'] as &$def) {
                if (is_array($def) && empty($def['class'])) {
                    $def['class'] = \hidev\controllers\CommonController::class;
                }
            }
        }

        // var_dump($config); die;

        return $config;
    }<commit_msg>fixed problem with request scriptFile caused by changed dir<commit_after><?php
/**
 * Automation tool mixed with code generator for easier continuous development
 *
 * @link      https://github.com/hiqdev/hidev
 * @package   hidev
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
 */

namespace hidev\base;

use hidev\components\Request;
use hidev\helpers\ConfigPlugin;
use hidev\helpers\FileHelper;
use Symfony\Component\Yaml\Yaml;
use Yii;
use yii\base\InvalidParamException;
use yii\helpers\ArrayHelper;

/**
 * Application starter.
 * Chdirs to the project's root directory and loads dependencies and configs.
 *
 * XXX it's important to distinguish:
 * - goals definitions (hidev config)
 * - application config
 */
class Starter
{
    /**
     * @var string absolute path to the project root directory
     */
    private $_rootDir;

    /**
     * @var array goals definitions
     */
    private $goals = [];

    private $hidevFiles = [];

    /**
     * @var array application config files
     */
    private $appFiles = ['@hidev/config/basis.php'];

    /**
     * Make action.
     */
    public function __construct()
    {
        $request = new Request();
        $this->scriptFile = $request->getScriptFile();
        list($route, $params) = $request->resolve();
        list($id, $subroute) = explode('/', $route, 2);
        if (in_array($id, ['init'], true)) {
            $this->noProject();
        } else {
            $this->startProject();
        }
    }

    public function noProject()
    {
    }

    public function startProject()
    {
        $this->getRootDir();
        $this->loadGoals();
        $this->addAliases();
        //  $this->addAutoloader();
        $this->requireAll();
        $this->includeAll();
        $this->moreConfig();
    }

    public function getConfig()
    {
        $config = ArrayHelper::merge($this->readConfig(), [
            'components' => $this->goals,
        ]);

        $config['components']['request']['scriptFile'] = $this->scriptFile;
        unset($config['include']);
        unset($config['components']['plugins']);

        foreach ($config['components'] as $id => $def) {
            if (empty($def['class'])) {
                unset($config['components'][$id]);
                $controllers[$id] = $def;
            }
        }
        $config = ArrayHelper::merge($config, [
            'controllerMap' => $controllers,
        ]);

        if (!empty($config['controllerMap'])) {
            foreach ($config['controllerMap'] as &$def) {
                if (is_array($def) && empty($def['class'])) {
                    $def['class'] = \hidev\controllers\CommonController::class;
                }
            }
        }

        // var_dump($config); die;

        return $config;
    }
{'fraction_non_alphanumeric': 0.15677655677655677, 'fraction_numerical': 0.003663003663003663, 'mean_word_length': 2.1694718514219384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, 'https://': 2, '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': '2057101', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1548, 'n_words': 344}