Liip\RMT\Command\BaseCommand::loadContext PHP Method

loadContext() public method

public loadContext ( )
    public function loadContext()
    {
        $configHandler = new Handler($this->getApplication()->getConfig(), $this->getApplication()->getProjectRootDir());
        $config = $configHandler->getBaseConfig();
        // Select a branch specific config if a VCS is in use
        if (isset($config['vcs'])) {
            Context::getInstance()->setService('vcs', $config['vcs']['class'], $config['vcs']['options']);
            /** @var VCSInterface $vcs */
            $vcs = Context::get('vcs');
            try {
                $branch = $vcs->getCurrentBranch();
            } catch (\Exception $e) {
                echo "Impossible to read the branch name";
            }
            if (isset($branch)) {
                $config = $configHandler->getConfigForBranch($branch);
            }
        }
        // Store the config for latter usage
        Context::getInstance()->setParameter('config', $config);
        // Populate the context
        foreach (array('version-generator', 'version-persister') as $service) {
            Context::getInstance()->setService($service, $config[$service]['class'], $config[$service]['options']);
        }
        foreach (array('prerequisites', 'pre-release-actions', 'post-release-actions') as $listName) {
            Context::getInstance()->createEmptyList($listName);
            foreach ($config[$listName] as $service) {
                Context::getInstance()->addToList($listName, $service['class'], $service['options']);
            }
        }
        // Provide the root dir as a context parameter
        Context::getInstance()->setParameter('project-root', $this->getApplication()->getProjectRootDir());
    }