<commit_before><?php

namespace mpr\client;

class helper
{
    static $mpr_root_filename = ".mprroot";

    /**
     * Get config array
     *
     * @return array|null Null on error
     */
    public function getConfig()
    {
        static $config;
        if($config == null) {
            $config = json_decode(file_get_contents(__DIR__ . "/config.json"), 1);
            if(!is_array($config)) {
                $this->writeLn("Error loading config.json!");
                exit(1);
            }
        }
        return $config;
    }

    protected function write($string)
    {
        echo $string;
    }

    protected function writeLn($string)
    {
        $this->write("{$string}\n");
    }

    protected function _searchOne($packageName)
    {
        $packageList = $this->_getPackageList();
        foreach($packageList as $package) {
            if($package['name'] == $packageName) {
                return $package;
            }
        }
        return null;
    }

    protected function findMe()
    {
        static $path_to_mpr;
        if($path_to_mpr == null) {
            $path_to_mpr = realpath(".");
            $found = false;
            while(!$found && $path_to_mpr != '/') {
                $found = in_array(self::$mpr_root_filename, scandir($path_to_mpr));
                if(!$found) {
                    $path_to_mpr = realpath($path_to_mpr . "/..");
                }
            }
            if(!$found) {
                $this->writeLn("[ERROR] Repository not found! Please try to execute `mpr init` in repository root path!");
                exit(1);
            }
        }
        return $path_to_mpr;
    }

    protected function getPackagePath($package, $pathType)
    {
        switch($pathType) {
            case "filename":
                return "{$package['name']}.phar";
            case "fileurl":
                return $this->getConfig()['host'] . "{$package['name']}/{$package['name']}.phar";
            case "destination_file":
                return "{$this->findMe()}{$package['package']['path']}{$package['name']}.phar";
            case "destination_folder":
                return "{$this->findMe()}{$package['package']['path']}";
        }
    }

    protected function _wget($url, $destination = null)
    {
        $this->write("Receiving {$url}...");
        try {
            $filename = basename($url);
            $auth = base64_encode($this->getConfig()['login'] . ':' . $this->getConfig()['password']);
            $header = ["Authorization: Basic {$auth}"];
            $opts = [
                'http' => [
                    'method' => 'GET',
                    'header' => $header
                ]
            ];
            $context = stream_context_create($opts);
            if($destination == null) {
                $result = file_get_contents($url, false, $context);
                if($result == false) {
                    $this->writeLn("Fail!");
                    return false;
                }
                $this->writeLn("OK!");
                return $result;
            } else {
                $fh = @fopen($url, 'rb', false, $context);
                if($fh == false) {
                    $this->writeLn("");
                    $this->writeLn("[ERROR] Error opening url. (Package broken?)");
                    return false;
                } else {
                    $this->writeLn("OK!");
                }
                $this->writeLn("Connection opened!");
                $bytesDownloaded = 0;
                $full_destination = "{$destination}{$filename}";
                if(!file_exists($destination)) {
                    mkdir($destination, 0777, true);
                }
                $dest = @fopen($full_destination, 'wb');
                if($dest == false) {
                    return $this->writeLn("[ERROR] Error opening destination path. (Check permissions?)");
                }
                while(!feof($fh)) {
                    $buffer = fread($fh, 4096);
                    if($buffer === false) {
                        return $this->writeLn("[ERROR] Error downloading content!");
                    }
                    $bytesDownloaded += strlen($buffer);
                    fwrite($dest, $buffer);
                    $this->write("\rDownloading content... [{$bytesDownloaded} bytes]");
                }
                $this->writeLn("");
                $this->writeLn("Content downloaded to {$full_destination}!");
                fclose($fh);
                fclose($dest);
                return true;
            }

        } catch(\Exception $e) {
            return false;
        }
    }
<commit_msg>install fixes. Add force install without dependencies etc.<commit_after><?php

namespace mpr\client;

class helper
{
    static $mpr_root_filename = ".mprroot";

    /**
     * Get config array
     *
     * @return array|null Null on error
     */
    public function getConfig()
    {
        static $config;
        if($config == null) {
            $config = json_decode(file_get_contents(__DIR__ . "/config.json"), 1);
            if(!is_array($config)) {
                $this->writeLn("Error loading config.json!");
                exit(1);
            }
        }
        return $config;
    }

    protected function write($string)
    {
        echo $string;
    }

    protected function writeLn($string)
    {
        $this->write("{$string}\n");
    }

    protected function _searchOne($packageName)
    {
        $packageList = $this->_getPackageList();
        foreach($packageList as $package) {
            if($package['name'] == $packageName) {
                return $package;
            }
        }
        return null;
    }

    protected function findMe()
    {
        static $path_to_mpr;
        if($path_to_mpr == null) {
            $path_to_mpr = realpath(".");
            $found = false;
            while(!$found && $path_to_mpr != '/') {
                $found = in_array(self::$mpr_root_filename, scandir($path_to_mpr));
                if(!$found) {
                    $path_to_mpr = realpath($path_to_mpr . "/..");
                }
            }
            if(!$found) {
                $this->writeLn("[ERROR] Repository not found! Please try to execute `mpr init` in repository root path!");
                exit(1);
            }
        }
        return $path_to_mpr;
    }

    protected function getPackagePath($package, $pathType)
    {
        switch($pathType) {
            case "filename":
                return "{$package['name']}.phar";
            case "fileurl":
                return $this->getConfig()['host'] . "{$package['name']}/{$package['name']}.phar";
            case "destination_file":
                return "{$this->findMe()}{$package['package']['path']}{$package['name']}.phar";
            case "destination_folder":
                return "{$this->findMe()}{$package['package']['path']}";
        }
    }

    protected function _wget($url, $destination = null)
    {
        $this->write("Receiving {$url}...");
        try {
            $filename = basename($url);
            $auth = base64_encode($this->getConfig()['login'] . ':' . $this->getConfig()['password']);
            $header = ["Authorization: Basic {$auth}"];
            $opts = [
                'http' => [
                    'method' => 'GET',
                    'header' => $header
                ]
            ];
            $context = stream_context_create($opts);
            if($destination == null) {
                $result = file_get_contents($url, false, $context);
                if($result == false) {
                    $this->writeLn("Fail!");
                    return false;
                }
                $this->writeLn("OK!");
                return $result;
            } else {
                $fh = @fopen($url, 'rb', false, $context);
                if($fh == false) {
                    $this->writeLn("");
                    $this->writeLn("[ERROR] Error opening url. (Package broken?)");
                    return false;
                } else {
                    $this->writeLn("OK!");
                }
                $bytesDownloaded = 0;
                $full_destination = "{$destination}{$filename}";
                if(!file_exists($destination)) {
                    mkdir($destination, 0777, true);
                }
                $dest = @fopen($full_destination, 'wb');
                if($dest == false) {
                    return $this->writeLn("[ERROR] Error opening destination path. (Check permissions?)");
                }
                while(!feof($fh)) {
                    $buffer = fread($fh, 4096);
                    if($buffer === false) {
                        return $this->writeLn("[ERROR] Error downloading content!");
                    }
                    $bytesDownloaded += strlen($buffer);
                    fwrite($dest, $buffer);
                    $this->write("\rDownloading content... [{$bytesDownloaded} bytes]");
                }
                $this->writeLn("");
                $this->writeLn("Content downloaded to {$full_destination}!");
                fclose($fh);
                fclose($dest);
                return true;
            }

        } catch(\Exception $e) {
            return false;
        }
    }

{'fraction_non_alphanumeric': 0.14998394176212396, 'fraction_numerical': 0.0029975377368590085, 'mean_word_length': 1.4120836560805576, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3552390', 'n_tokens_mistral': 2583, 'n_tokens_neox': 2436, 'n_words': 463}