?????????? ????????? - ??????????????? - /home/agenciai/public_html/cd38d8/Phar.zip
???????
PK ��'\'B٩ � TargetPhar.phpnu �[��� <?php namespace Clue\PharComposer\Phar; use Clue\PharComposer\Package\Bundle; /** * Represents the target phar to be created. */ class TargetPhar { /** @var \Phar */ private $phar; /** @var PharComposer */ private $pharComposer; public function __construct(\Phar $phar, PharComposer $pharComposer) { $phar->startBuffering(); $this->phar = $phar; $this->pharComposer = $pharComposer; } /** * finalize writing of phar file */ public function stopBuffering() { $this->phar->stopBuffering(); } /** * adds given list of resources to phar * * @param Bundle $bundle */ public function addBundle(Bundle $bundle) { foreach ($bundle as $resource) { if (is_string($resource)) { $this->addFile($resource); } else { $this->buildFromIterator($resource); } } } /** * Adds a file to the Phar * * @param string $file The file name. */ public function addFile($file) { $this->phar->addFile($file, $this->pharComposer->getPathLocalToBase($file)); } public function buildFromIterator(\Traversable $iterator) { $this->phar->buildFromIterator($iterator, $this->pharComposer->getPackageRoot()->getDirectory()); } /** * Used to set the PHP loader or bootstrap stub of a Phar archive * * @param string $stub */ public function setStub($stub) { $this->phar->setStub($stub); } public function addFromString($local, $contents) { $this->phar->addFromString($local, $contents); } } PK ��'\"6�f* f* Packager.phpnu �[��� <?php namespace Clue\PharComposer\Phar; use Symfony\Component\Process\Process; use Symfony\Component\Process\ExecutableFinder; use UnexpectedValueException; use InvalidArgumentException; use RuntimeException; use Symfony\Component\Console\Output\OutputInterface; use Clue\PharComposer\Package\Package; class Packager { const PATH_BIN = '/usr/local/bin'; private $output; private $binSudo = 'sudo'; public function __construct() { $this->setOutput(true); } private function log($message) { $fn = $this->output; $fn($message . PHP_EOL); } public function setBinSudo($bin) { $this->binSudo = $bin; } /** * @param OutputInterface|bool|callable $fn */ public function setOutput($fn) { if ($fn instanceof OutputInterface) { $fn = function ($line) use ($fn) { $fn->write($line); }; } elseif ($fn === true) { $fn = function ($line) { echo $line; }; } elseif ($fn === false) { $fn = function () { }; } $this->output = $fn; } /** * ensure writing phar files is enabled or respawn with PHP setting which allows writing * * @param int $wait * @return void * @uses assertWritable() */ public function coerceWritable($wait = 1) { try { $this->assertWritable(); } catch (UnexpectedValueException $e) { if (!function_exists('pcntl_exec')) { $this->log('<error>' . $e->getMessage() . '</error>'); return; } $this->log('<info>' . $e->getMessage() . ', trying to re-spawn with correct config</info>'); if ($wait) { sleep($wait); } $args = array_merge(array('php', '-d phar.readonly=off'), $_SERVER['argv']); if (pcntl_exec('/usr/bin/env', $args) === false) { $this->log('<error>Unable to switch into new configuration</error>'); return; } } } /** * ensure writing phar files is enabled or throw an exception * * @throws UnexpectedValueException */ public function assertWritable() { if (ini_get('phar.readonly') === '1') { throw new UnexpectedValueException('Your configuration disabled writing phar files (phar.readonly = On), please update your configuration or run with "php -d phar.readonly=off ' . $_SERVER['argv'][0].'"'); } } /** * @param string $path * @param string $version * @return PharComposer * @throws UnexpectedValueException * @throws InvalidArgumentException * @throws RuntimeException */ public function getPharer($path, $version = null) { if ($version !== null) { // TODO: should be the other way around $path .= ':' . $version; } $step = 1; $steps = 1; if ($this->isPackageUrl($path)) { $url = $path; $version = null; $steps = 3; if (preg_match('/(.+)\:((?:dev\-|v\d)\S+)$/i', $url, $match)) { $url = $match[1]; $version = $match[2]; if (substr($version, 0, 4) === 'dev-') { $version = substr($version, 4); } } $path = $this->getDirTemporary(); $finder = new ExecutableFinder(); $git = escapeshellarg($finder->find('git', 'git')); $that = $this; $this->displayMeasure( '[' . $step++ . '/' . $steps.'] Cloning <info>' . $url . '</info> into temporary directory <info>' . $path . '</info>', function() use ($that, $url, $path, $version, $git) { $that->exec($git . ' clone ' . escapeshellarg($url) . ' ' . escapeshellarg($path)); if ($version !== null) { $this->exec($git . ' checkout ' . escapeshellarg($version) . ' 2>&1', $path); } }, 'Cloning base repository completed' ); $pharcomposer = new PharComposer($path . '/composer.json'); $package = $pharcomposer->getPackageRoot()->getName(); if (is_file('composer.phar')) { $command = escapeshellarg($finder->find('php', 'php')) . ' composer.phar'; } else { $command = escapeshellarg($finder->find('composer', 'composer')); } $command .= ' install --no-dev --no-progress --no-scripts'; $this->displayMeasure( '[' . $step++ . '/' . $steps.'] Installing dependencies for <info>' . $package . '</info> into <info>' . $path . '</info> (using <info>' . $command . '</info>)', function () use ($that, $command, $path) { try { $that->exec($command, $path); } catch (UnexpectedValueException $e) { throw new UnexpectedValueException('Installing dependencies via composer failed', 0, $e); } }, 'Downloading dependencies completed' ); } elseif ($this->isPackageName($path)) { if (is_dir($path)) { $this->log('<info>There\'s also a directory with the given name</info>'); } $steps = 2; $package = $path; $path = $this->getDirTemporary(); $finder = new ExecutableFinder(); if (is_file('composer.phar')) { $command = escapeshellarg($finder->find('php', 'php')) . ' composer.phar'; } else { $command = escapeshellarg($finder->find('composer', 'composer')); } $command .= ' create-project ' . escapeshellarg($package) . ' ' . escapeshellarg($path) . ' --no-dev --no-progress --no-scripts'; $that = $this; $this->displayMeasure( '[' . $step++ . '/' . $steps.'] Installing <info>' . $package . '</info> to temporary directory <info>' . $path . '</info> (using <info>' . $command . '</info>)', function () use ($that, $command) { try { $that->exec($command); } catch (UnexpectedValueException $e) { throw new UnexpectedValueException('Installing package via composer failed', 0, $e); } }, 'Downloading package completed' ); } if (is_dir($path)) { $path = rtrim($path, '/') . '/composer.json'; } if (!is_file($path)) { throw new InvalidArgumentException('The given path "' . $path . '" is not a readable file'); } $pharer = new PharComposer($path); $pharer->setOutput($this->output); $pharer->setStep($step); $pathVendor = $pharer->getPackageRoot()->getDirectory() . $pharer->getPackageRoot()->getPathVendor(); if (!is_dir($pathVendor)) { throw new RuntimeException('Project is not installed via composer. Run "composer install" manually'); } return $pharer; } public function measure($fn) { $time = microtime(true); $fn(); return max(microtime(true) - $time, 0); } public function displayMeasure($title, $fn, $success) { $this->log($title); $time = $this->measure($fn); $this->log(''); $this->log(' <info>OK</info> - ' . $success .' (after ' . round($time, 1) . 's)'); } /** * @param string $cmd * @param ?string $chdir * @return void * @throws UnexpectedValueException */ public function exec($cmd, $chdir = null) { $nl = true; // $output = $this->output; // Symfony 5+ requires 'fromShellCommandline', older versions support direct instantiation with command line // @codeCoverageIgnoreStart try { new \ReflectionMethod('Symfony\Component\Process\Process', 'fromShellCommandline'); $process = Process::fromShellCommandline($cmd, $chdir); } catch (\ReflectionException $e) { $process = new Process($cmd, $chdir); } // @codeCoverageIgnoreEnd $process->setTimeout(null); $code = $process->run(function($type, $data) use ($output, &$nl) { if ($nl === true) { $data = PHP_EOL . $data; $nl = false; } if (substr($data, -1) === "\n") { $nl = true; $data = substr($data, 0, -strlen(PHP_EOL)); } $data = str_replace("\n", "\n ", $data); $output($data); }); if ($nl) { $this->log(''); } if ($code !== 0) { throw new UnexpectedValueException('Error status code: ' . $process->getExitCodeText() . ' (code ' . $code . ')'); } } public function install(PharComposer $pharer, $path) { $pharer->build(); $this->log('Move resulting phar to <info>' . $path . '</info>'); $this->exec($this->binSudo . ' -- mv -f ' . escapeshellarg($pharer->getTarget()) . ' ' . escapeshellarg($path)); $this->log(''); $this->log(' <info>OK</info> - Moved to <info>' . $path . '</info>'); } /** * @param Package $package * @param ?string $path * @return string */ public function getSystemBin(Package $package, $path = null) { // no path given => place in system bin path if ($path === null) { $path = self::PATH_BIN; } // no slash => path is relative to system bin path if (strpos($path, '/') === false) { $path = self::PATH_BIN . '/' . $path; } // path is actually a directory => append package name if (is_dir($path)) { $path = rtrim($path, '/') . '/' . $package->getShortName(); } return $path; } private function isPackageName($path) { return !!preg_match('/^[^\s\/]+\/[^\s\/]+(\:[^\s]+)?$/i', $path); } public function isPackageUrl($path) { return (strpos($path, '://') !== false && @parse_url($path) !== false) || preg_match('/^[^-\/\s][^:\/\s]*:[^\s\\\\]\S*/', $path); } private function getDirTemporary() { $path = sys_get_temp_dir() . '/phar-composer' . mt_rand(0,9); while (is_dir($path)) { $path .= mt_rand(0, 9); } return $path; } } PK ��'\��>�# �# PharComposer.phpnu �[��� <?php namespace Clue\PharComposer\Phar; use Clue\PharComposer\Logger; use Clue\PharComposer\Package\Package; use Clue\PharComposer\Box\StubGenerator; /** * The PharComposer is responsible for collecting options and then building the target phar */ class PharComposer { private $package; private $main = null; private $target = null; private $logger; private $step = '?'; /** * @param string $path path to composer.json file * @throws \InvalidArgumentException when given $path can not be parsed as JSON */ public function __construct($path) { $this->package = new Package($this->loadJson($path), dirname(realpath($path))); $this->logger = new Logger(); } /** * set output function to use to output log messages * * @param callable|boolean $output callable that receives a single $line argument or boolean echo */ public function setOutput($output) { $this->logger->setOutput($output); } /** * Get path to target phar file (absolute path or relative to current directory) * * @return string */ public function getTarget() { if ($this->target === null) { $this->target = $this->package->getShortName() . '.phar'; } return $this->target; } /** * Set path to target phar file (absolute path or relative to current directory) * * If the given path is a directory, the default target (package short name) * will be appended automatically. * * @param string $target * @return $this */ public function setTarget($target) { // path is actually a directory => append package name if (is_dir($target)) { $this->target = null; $target = rtrim($target, '/') . '/' . $this->getTarget(); } $this->target = $target; return $this; } /** * Get path to main bin (relative to package directory) * * @return string * @throws \UnexpectedValueException */ public function getMain() { if ($this->main === null) { foreach ($this->package->getBins() as $path) { if (!file_exists($this->package->getDirectory() . $path)) { throw new \UnexpectedValueException('Bin file "' . $path . '" does not exist'); } $this->main = $path; break; } } return $this->main; } /** * set path to main bin (relative to package directory) * * @param string $main * @return $this */ public function setMain($main) { $this->main = $main; return $this; } /** * * @return Package */ public function getPackageRoot() { return $this->package; } /** * * @return Package[] */ public function getPackagesDependencies() { $packages = array(); $pathVendor = $this->package->getDirectory() . $this->package->getPathVendor(); // load all installed packages (use installed.json which also includes version instead of composer.lock) if (is_file($pathVendor . 'composer/installed.json')) { // file does not exist if there's nothing to be installed $installed = $this->loadJson($pathVendor . 'composer/installed.json'); // Composer 2.0 format wrapped in additional root key if (isset($installed['packages'])) { $installed = $installed['packages']; } foreach ($installed as $package) { $dir = $package['name'] . '/'; if (isset($package['target-dir'])) { $dir .= trim($package['target-dir'], '/') . '/'; } $dir = $pathVendor . $dir; $packages []= new Package($package, $dir); } } return $packages; } public function build() { $this->log('[' . $this->step . '/' . $this->step.'] Creating phar <info>' . $this->getTarget() . '</info>'); $time = microtime(true); $pathVendor = $this->package->getDirectory() . $this->package->getPathVendor(); if (!is_dir($pathVendor)) { throw new \RuntimeException('Directory "' . $pathVendor . '" not properly installed, did you run "composer install"?'); } // get target and tempory file name to write to $target = $this->getTarget(); do { $tmp = $target . '.' . mt_rand() . '.phar'; } while (file_exists($tmp)); $targetPhar = new TargetPhar(new \Phar($tmp), $this); $this->log(' - Adding main package "' . $this->package->getName() . '"'); $targetPhar->addBundle($this->package->bundle()); $this->log(' - Adding composer base files'); // explicitly add composer autoloader $targetPhar->addFile($pathVendor . 'autoload.php'); // only add composer base directory (no sub-directories!) $targetPhar->buildFromIterator(new \GlobIterator($pathVendor . 'composer/*.*', \FilesystemIterator::KEY_AS_FILENAME)); foreach ($this->getPackagesDependencies() as $package) { $this->log(' - Adding dependency "' . $package->getName() . '" from "' . $this->getPathLocalToBase($package->getDirectory()) . '"'); $targetPhar->addBundle($package->bundle()); } $this->log(' - Setting main/stub'); $chmod = 0755; $main = $this->getMain(); if ($main === null) { $this->log(' WARNING: No main bin file defined! Resulting phar will NOT be executable'); } else { $generator = StubGenerator::create() ->index($main) ->extract(true) ->banner("Bundled by phar-composer with the help of php-box.\n\n@link https://github.com/clue/phar-composer"); $lines = file($this->package->getDirectory() . $main, FILE_IGNORE_NEW_LINES); if (substr($lines[0], 0, 2) === '#!') { $this->log(' Using referenced shebang "'. $lines[0] . '"'); $generator->shebang($lines[0]); // remove shebang from main file and add (overwrite) unset($lines[0]); $targetPhar->addFromString($main, implode("\n", $lines)); } $targetPhar->setStub($generator->generate()); $chmod = octdec(substr(decoct(fileperms($this->package->getDirectory() . $main)),-4)); $this->log(' Using referenced chmod ' . sprintf('%04o', $chmod)); } // stop buffering contents in memory and write to file // failure to write will emit a warning (ignore) and throw an (uncaught) exception try { @$targetPhar->stopBuffering(); $targetPhar = null; } catch (\PharException $e) { throw new \RuntimeException('Unable to write phar: ' . $e->getMessage()); } if ($chmod !== null) { $this->log(' Applying chmod ' . sprintf('%04o', $chmod)); if (chmod($tmp, $chmod) === false) { throw new \UnexpectedValueException('Unable to chmod target file "' . $target .'"'); } } if (file_exists($target)) { $this->log(' - Overwriting existing file <info>' . $target . '</info> (' . $this->getSize($target) . ')'); } if (@rename($tmp, $target) === false) { // retry renaming after sleeping to give slow network drives some time to flush data sleep(5); if (rename($tmp, $target) === false) { throw new \UnexpectedValueException('Unable to rename temporary phar archive to "'.$target.'"'); } } $time = max(microtime(true) - $time, 0); $this->log(''); $this->log(' <info>OK</info> - Creating <info>' . $this->getTarget() .'</info> (' . $this->getSize($this->getTarget()) . ') completed after ' . round($time, 1) . 's'); } private function getSize($path) { return round(filesize($path) / 1024, 1) . ' KiB'; } public function getPathLocalToBase($path) { $root = $this->package->getDirectory(); if (strpos($path, $root) !== 0) { throw new \UnexpectedValueException('Path "' . $path . '" is not within base project path "' . $root . '"'); } return substr($path, strlen($root)); } public function log($message) { $this->logger->log($message); } public function setStep($step) { $this->step = $step; } /** * @param string $path * @return mixed * @throws \InvalidArgumentException */ private function loadJson($path) { $ret = @json_decode(file_get_contents($path), true); if ($ret === null) { throw new \InvalidArgumentException('Unable to parse given path "' . $path . '"', json_last_error()); } return $ret; } } PK ��'\'B٩ � TargetPhar.phpnu �[��� PK ��'\"6�f* f* � Packager.phpnu �[��� PK ��'\��>�# �# �1 PharComposer.phpnu �[��� PK � mU
| ver. 1.6 |
Github
|
.
| PHP 8.2.30 | ??????????? ?????????: 0 |
proxy
|
phpinfo
|
???????????