Compile message catalog to binary format
@param string $file
@param string $path
@return array
@throws \Exception
517998
protected function compile($file,$path)
    {
        $results = array();

        // if .tmp file exists, clean it for further using it as cache
        if (file_exists("$path.tmp")) {
            unlink("$path.tmp");
        }
        $options = implode(' ',array(
            '--check',
            "-o $path.tmp",
            $file,
        ));

        $process = new Process('msgfmt '.$options);
        $process->run();
        $output = $process->getOutput();
        if (!$process->isSuccessful()) {
            throw new \Exception($process->getErrorOutput());
        }

        if (!file_exists("$path.tmp")) {
            throw new \Exception('msgfmt failed to compile messages for translating. Did you install gettext?');
        }
        rename("$path.tmp", $path);
        $results[$this->relative($file)] = 'Scanned';
        $results[$this->relative($path)] = 'Written';

        return $results;
    }
486163
private static function convertFileToClass(string $file)
    {
        $fh = fopen($file, 'r');

        $namespace = '';

        while(($line = fgets($fh, 5000)) !== false) {

            if (str_contains($line, 'namespace')) {
                $namespace = trim(str_replace(['namespace', ';'], '', $line));
                break;
            }
        }

        fclose($fh);

        $class = basename(str_replace('.php', '', $file));

        return $namespace.'\\'.$class;
    }
470974
public static function isBinary($path)
    {
        self::fullpath($path);

        $size = filesize($path);

        if ($size >= 0 && $size < 2) {
            return false;
        }

        $finfo  = finfo_open(FILEINFO_MIME_ENCODING);
        $encode = finfo_buffer($finfo, file_get_contents($path, false, null, 0, 5012));
        finfo_close($finfo);

        return strcasecmp($encode, 'binary') === 0;
    }
1027458
function binary($path) {
        if (function_exists('exec')) {
            exec($path.' -v 2>&1',$out,$ret);
            if ($ret==0 && preg_match('/cli/',@$out[0],$out))
                $this->binary=$path;
        }
        return $this->binary;
    }
691241
public static function load($path, $file = '.env')
        {
            if (!is_string($file)) {
                $file = '.env';
            }

            $filePath = rtrim($path, '/') . '/' . $file;

            if (!is_readable($filePath) || !is_file($filePath)) {
                throw new \InvalidArgumentException(
                    sprintf(
                        "Dotenv: Environment file %s not found or not readable. " .
                        "Create file with your environment settings at %s",
                        $file,
                        $filePath
                    )
                );
            }

            // Read file into an array of lines with auto-detected line endings
            $autodetect = ini_get('auto_detect_line_endings');

            ini_set('auto_detect_line_endings', '1');

            $lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

            ini_set('auto_detect_line_endings', $autodetect);

            foreach ($lines as $line) {
                // Disregard comments
                if (strpos(trim($line), '#') === 0) {
                    continue;
                }
                // Only use non-empty lines that look like setters
                if (strpos($line, '=') !== false) {
                    static::setEnvironmentVariable($line);
                }
            }
        }
1008679
protected static function _parse($file) {
		$header = '';
		$content = '';

		if (!$stream = fopen($file, 'r')) {
			throw new Exception('Failed to open file.');
		}

		$isHeader = false;

		while (!feof($stream)) {
			$line = rtrim(fgets($stream));

			if ($line === '---') {
				$isHeader = !$isHeader;
				continue;
			}
			if ($isHeader) {
				$header .= $line . "\n";
			} else {
				$content .= $line . "\n";
			}
		}
		if ($header) {
			$info = Yaml::parse($header);
		} else {
			$info = [];
		}

		fclose($stream);
		return [$info, $content];
	}
186843
public function compileFileIntoElement($path)
    {
        $path = $this->resolve($path);

        return $this->compileIntoElement($this->getFileContents($path), $path);
    }
352951
public static function assertIsExecutable(string $path, Throwable $exception): string
    {
        static::makeAssertion(\is_executable($path), $exception);
        return $path;
    }
705549
private function parseFileName($path, $file) {
		$result = Array();
		if (is_dir($path.'/'.$file)) {
			$result['name'] = $file;
			$result['ext'] = 'dir';
			$result['is_dir'] = 1;
		} else {
			$pos = strrpos($file, '.');
			$result['name'] = substr($file, 0, $pos);
			$result['ext'] = substr($file, $pos + 1);
			$result['is_dir'] = 0;
		}
		return $result;
	}
534181
public static function decodeFromFile($path)
    {
        if (!is_file($path)) {
            throw new \Exception("File does not exist: {$path}");
        }

        $string = file_get_contents($path);

        if ($string === false) {
            throw new \Exception("Failed to read the file: {$path}");
        }

        if (!$string) {
            return [];
        }

        $array = json_decode($string, true);

        static::checkLastError();

        return $array;
    }
603444
public static function group(String $file)
    {
        $file = self::rpath($file);

        if( ! file_exists($file) )
        {
            throw new Exception\FileNotFoundException(NULL, $file);
        }

        $group = filegroup($file);

        if( function_exists('posix_getgrgid') )
        {
            return posix_getgrgid($group);
        }
        else
        {
            return $group;
        }
    }
453033
public function get($file)
    {
        $target = $this->path . $file;

        if (!is_readable($target)) {
            throw new \Exception("No such content " . $target);
        }

        return file_get_contents($target);
    }
1242643
protected function extract($file, $path)
	{
		// we must use cmdline tar, as PharData::extract() messes up symlinks
		$command = 'tar -xzf ' . ProcessExecutor::escape($file) . ' -C ' . ProcessExecutor::escape($path);

		if (0 === $this->process->execute($command, $ignoredOutput)) {
			return;
		}

		throw new \RuntimeException("Failed to execute '$command'\n\n" . $this->process->getErrorOutput());
	}
1258972
protected function convert(string $file): void
    {
        $routes = Yaml::parse(file_get_contents($file));

        $year = Chronos::create()->year;

        $tmpl = <<<PHP
<?php
/**
 * Part of Windwalker project.
 *
 * @copyright  Copyright (C) $year __ORGANIZATION__.
 * @license    __LICENSE__
 */

use Windwalker\Core\Router\RouteCreator;

/** @var \$router RouteCreator */

PHP;

        foreach ($routes as $name => $route) {
            $code = '// ' . str(StringNormalise::toSpaceSeparated($name))->upperCaseWords() . "\n";
            $code .= "\$router->any('$name', '{$route['pattern']}')";

            if (isset($route['controller'])) {
                $code .= "\n" . $this->indent(1) . "->controller('{$route['controller']}')";
            }

            if (isset($route['variables'])) {
                $vars = $this->indent(1, PhpFormat::structToString($route['variables'], ['as_array' => true]));

                $code .= "\n" . $this->indent(1) . "->variables({$vars})";
            }

            if (isset($route['requirements'])) {
                $vars = $this->indent(1, PhpFormat::structToString($route['requirements'], ['as_array' => true]));

                $code .= "\n" . $this->indent(1) . "->requirements({$vars})";
            }

            if (isset($route['methods'])) {
                $vars = $this->indent(1, PhpFormat::structToString($route['methods'], ['as_array' => true]));

                $code .= "\n" . $this->indent(1) . "->methods({$vars})";
            }

            if (isset($route['action'])) {
                foreach ($route['action'] as $methods => $action) {
                    $methods = array_map('trim', explode('|', $methods));

                    foreach ($methods as $method) {
                        $method = strtolower($method);

                        if ($method === '*') {
                            $code .= "\n" . $this->indent(1) . "->allActions('{$action}')";
                        } else {
                            $code .= "\n" . $this->indent(1) . "->{$method}Action('{$action}')";
                        }
                    }
                }
            }

            if (isset($route['scheme'])) {
                $code .= "\n" . $this->indent(1) . "->scheme('{$route['scheme']}')";
            }

            if (isset($route['port'])) {
                $code .= "\n" . $this->indent(1) . "->port('{$route['port']}')";
            }

            if (isset($route['sslPort'])) {
                $code .= "\n" . $this->indent(1) . "->sslPort('{$route['sslPort']}')";
            }

            if (isset($route['extra'])) {
                $vars = $this->indent(1, PhpFormat::structToString($route['extra'], ['as_array' => true]));

                $code .= "\n" . $this->indent(1) . "->extraValues({$vars})";
            }

            $code .= ';';

            $tmpl .= "\n" . $code . "\n";
        }

        $dest = preg_replace('/\.[^.]+$/', '.', $file) . 'php';

        file_put_contents($dest, $tmpl);

        $this->out(sprintf('[Convert] <info>%s</info>', $dest));
    }
288722
public function unzip($file, $path)
    {
        if (ends_with($file, '.zip')) {
            $this->message("Unzipping to {$file}");

            $this->unzipFile($file, $path);
        }
    }
375194
public function moveFile($file, $path = '')
    {
        $name = token();
        $extension = $file->guessClientExtension();

        $filename = $name . '.' . $extension;
        $imageTmp = Image::make($file->getRealPath());

        if (!$imageTmp) {
            return notify()->error('Oops', 'Something went wrong', 'warning shake animated');
        }

        $path = upload_path_images($path);
        $image = $imageTmp->save($path . $filename);

        return $filename;
    }
1369899
public function validateFile($file)
    {
        if (file_exists($file) !== true) {
            throw new Exception('File not found');
        }
        if (is_readable($file) !== true) {
            throw new Exception('File not readable');
        }

        $data = file_get_contents($file);
        if ($data === false) {
            throw new Exception('Failed get file');
        }

        return $this->validateFragment($data);
    }