<commit_before><?php
/*
 * This file is part of the CampaignChain package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CampaignChain\CoreBundle\Module;

use Symfony\Component\Process\Process;

class Composer
{
    private $root;
    private $logger;

    public function __construct($kernelRootDir, $logger)
    {
        $this->root = $kernelRootDir.
                        DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR;
        $this->logger = $logger;
    }

    public function requirePackages(array $packages)
    {
        if(!count($packages)){
            return false;
        }

        $packagesArg = '';

        foreach($packages as $package){
            $packagesArg .= $package['name'].':'.$package['version'].' ';
        }

        /*
         * TODO: Enhance for multiple repositories.
         *
         * Check whether the package and repository actually exist and that
         * the package exists in the repository.
         */

        ob_start();
        $currentDir = getcwd();
        chdir($this->root);
        system('composer require '.$packagesArg, $output);
        chdir($currentDir);
        $this->logger->info(ob_get_clean());

        // TODO: Check if new package is in lock file.<commit_msg>CE-68 Module installation: Implement versioning<commit_after><?php
/*
 * This file is part of the CampaignChain package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CampaignChain\CoreBundle\Module;

use Symfony\Component\Process\Process;

class Composer
{
    private $root;
    private $logger;

    public function __construct($kernelRootDir, $logger)
    {
        $this->root = $kernelRootDir.
                        DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR;
        $this->logger = $logger;
    }

    public function requirePackages(array $packages)
    {
        if(!count($packages)){
            return false;
        }

        $packagesArg = '';

        foreach($packages as $package){
            $packagesArg .= $package['name'].':'.$package['version'].' ';
        }

        /*
         * TODO: Enhance for multiple repositories.
         *
         * Check whether the package and repository actually exist and that
         * the package exists in the repository.
         */

        ob_start();
        $currentDir = getcwd();
        chdir($this->root);
        system('composer require '.$packagesArg, $output);
        chdir($currentDir);
        $this->logger->info('Output of: composer require '.$packagesArg);
        $this->logger->info(ob_get_clean());

        // TODO: Check if new package is in lock file.
{'fraction_non_alphanumeric': 0.11978798586572438, 'fraction_numerical': 0.0007067137809187279, 'mean_word_length': 2.291860465116279, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '1312454', 'n_tokens_mistral': 770, 'n_tokens_neox': 747, 'n_words': 214}