1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-26 21:34:41 +01:00

Improve pure phar installs

This commit is contained in:
Daniil Gentili 2023-07-09 18:42:42 +02:00
parent b8bc4cafe5
commit 8fd4aa7e2d
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 51 additions and 7 deletions

View File

@ -6,6 +6,7 @@ namespace danog\MadelineProto\Ipc\Runner;
use Phar;
use const MADELINE_PHAR;
use const MADELINE_PHP;
/**
@ -29,6 +30,12 @@ abstract class RunnerAbstract
if (\defined('MADELINE_PHP')) {
return MADELINE_PHP;
}
/**
* If using madeline.phar, simply return madeline.phar path.
*/
if (\defined('MADELINE_PHAR')) {
return MADELINE_PHAR;
}
// Write process runner to external file if inside a PHAR different from madeline.phar,
// because PHP can't open files inside a PHAR directly except for the stub.
if (\strpos(self::SCRIPT_PATH, 'phar://') === 0) {

View File

@ -25,12 +25,53 @@ $p->addFromString('.git/refs/heads/v8', $argv[3]);
$p->setStub('<?php
if ((PHP_MAJOR_VERSION === 8 && PHP_MINOR_VERSION < 1) || PHP_MAJOR_VERSION <= 7) {
die("MadelineProto requires at least PHP 8.1.".PHP_EOL);
}
if (PHP_INT_SIZE < 8) {
die("A 64-bit build of PHP is required to run MadelineProto, PHP 8.1 is required.".PHP_EOL);
}
if (\defined("MADELINE_PHAR")) {
throw new \Exception("Please do not include madeline.phar twice, use require_once \'madeline.phar\';!");
}
if (!\defined(\'MADELINE_ALLOW_COMPOSER\') && \class_exists(\Composer\Autoload\ClassLoader::class)) {
throw new \Exception(\'Composer autoloader detected: madeline.phar is incompatible with Composer, please install MadelineProto using composer: https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-existing-project\');
}
\define(\'MADELINE_PHAR\', __FILE__);
if (defined("MADELINE_REAL_ROOT")) {
@chdir(MADELINE_REAL_ROOT);
} else {
$backtrace = \debug_backtrace(0);
if (\count($backtrace) === 1) {
if (isset($GLOBALS["argv"]) && !empty($GLOBALS["argv"])) {
$arguments = \array_slice($GLOBALS["argv"], 1);
} elseif (isset($_GET["argv"]) && !empty($_GET["argv"])) {
$arguments = $_GET["argv"];
} else {
$arguments = [];
}
if (\count($arguments) >= 2) {
\define(\MADELINE_WORKER_TYPE::class, \array_shift($arguments));
\define(\MADELINE_WORKER_ARGS::class, $arguments);
} else {
die("MadelineProto loader: you must include this file in another PHP script, see https://docs.madelineproto.xyz for more info.".PHP_EOL);
}
\define("MADELINE_REAL_ROOT", \dirname($backtrace[0]["file"]));
}
}
Phar::interceptFileFuncs();
Phar::mapPhar("'.$argv[2].'");
return require_once "phar://'.$argv[2].'/vendor/autoload.php";
$result = require_once "phar://'.$argv[2].'/vendor/autoload.php";
if (\defined("MADELINE_WORKER_TYPE") && \constant("MADELINE_WORKER_TYPE") === "madeline-ipc") {
require_once "phar://'.$argv[2].'/vendor/danog/madelineproto/src/Ipc/Runner/entry.php";
}
return $result;
__HALT_COMPILER(); ?>');

View File

@ -7,7 +7,7 @@ if (\defined('MADELINE_PHP')) {
}
if (!\defined('MADELINE_ALLOW_COMPOSER') && \class_exists(\Composer\Autoload\ClassLoader::class)) {
throw new \Exception('Composer autoloader detected: madeline.php is incompatible with Composer, please require \'danog/madelineproto:^7\' using composer.');
throw new \Exception('Composer autoloader detected: madeline.php is incompatible with Composer, please install MadelineProto using composer: https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-existing-project');
}
\define('MADELINE_PHP', __FILE__);
@ -169,11 +169,7 @@ class Installer
self::$lock = \fopen("$phar.lock", 'c');
}
\flock(self::$lock, LOCK_SH);
$result = require_once $phar;
if (\defined('MADELINE_WORKER_TYPE') && \constant('MADELINE_WORKER_TYPE') === 'madeline-ipc') {
require_once "phar://$phar/vendor/danog/madelineproto/src/Ipc/Runner/entry.php";
}
return $result;
return require_once $phar;
}
/**