|
|
|
@ -2,53 +2,76 @@
|
|
|
|
|
|
|
|
|
|
use Spip\Loader\Debug;
|
|
|
|
|
|
|
|
|
|
$debug = false;
|
|
|
|
|
final class Spip_Loader_Phar_Bootstrap {
|
|
|
|
|
const VERSION = '';
|
|
|
|
|
const DATE = '';
|
|
|
|
|
const COMPILATION_DATE = '';
|
|
|
|
|
const DEBUG = false;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Phar::mapPhar('spip_loader.phar');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
require 'phar://spip_loader.phar/vendor/autoload.php';
|
|
|
|
|
} catch (\Error $e) {
|
|
|
|
|
// @note \Error is PHP7+… (quid de PHP 5.6 ?)
|
|
|
|
|
if (!(
|
|
|
|
|
function_exists('opcache_get_status')
|
|
|
|
|
const NAME = 'spip_loader.phar';
|
|
|
|
|
const AUTOLOADER = 'phar://spip_loader.phar/vendor/autoload.php';
|
|
|
|
|
|
|
|
|
|
public function init() {
|
|
|
|
|
Phar::mapPhar(self::NAME);
|
|
|
|
|
$this->start_autoloader();
|
|
|
|
|
Debug::add('VERSION', self::VERSION);
|
|
|
|
|
Debug::add('DATE', self::DATE);
|
|
|
|
|
Debug::add('COMPILATION_DATE', self::COMPILATION_DATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return bool */
|
|
|
|
|
private function is_opcache_enabled() {
|
|
|
|
|
return function_exists('opcache_get_status')
|
|
|
|
|
&& opcache_get_status()
|
|
|
|
|
&& (opcache_get_status()['opcache_enabled'])
|
|
|
|
|
&& false !== strpos($e->getMessage(), sprintf('Failed opening required \'%s\'', 'phar://spip_loader.phar/vendor/autoload.php'))
|
|
|
|
|
)) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
&& (opcache_get_status()['opcache_enabled']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function has_failed_autoloader(\Error $e) {
|
|
|
|
|
return false !== strpos($e->getMessage(), sprintf('Failed opening required \'%s\'', self::AUTOLOADER));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// some hosting failed re-opening inside phar files :/
|
|
|
|
|
@ini_set('opcache.enable', 0);
|
|
|
|
|
private function start_autoloader() {
|
|
|
|
|
try {
|
|
|
|
|
require 'phar://spip_loader.phar/vendor/autoload.php';
|
|
|
|
|
Debug::add('Disable opcache', 'Script disable opcache to start the Loader');
|
|
|
|
|
require self::AUTOLOADER;
|
|
|
|
|
} catch (\Error $e) {
|
|
|
|
|
if (!(
|
|
|
|
|
function_exists('opcache_reset')
|
|
|
|
|
&& false !== strpos($e->getMessage(), sprintf('Failed opening required \'%s\'', 'phar://spip_loader.phar/vendor/autoload.php'))
|
|
|
|
|
)) {
|
|
|
|
|
if ($this->is_opcache_enabled() && $this->has_failed_autoloader($e)) {
|
|
|
|
|
// some hosting failed re-opening inside phar files :/
|
|
|
|
|
@ini_set('opcache.enable', 0);
|
|
|
|
|
try {
|
|
|
|
|
require 'phar://spip_loader.phar/vendor/autoload.php';
|
|
|
|
|
Debug::add('Disable opcache', 'Script disable opcache to start the Loader');
|
|
|
|
|
} catch (\Error $e) {
|
|
|
|
|
if (function_exists('opcache_reset') && $this->has_failed_autoloader($e)) {
|
|
|
|
|
opcache_reset(); // brutality mode :/
|
|
|
|
|
require 'phar://spip_loader.phar/vendor/autoload.php';
|
|
|
|
|
Debug::add('Reset opcache', 'Script reset opcache to start the Loader (really bad thing 😢)');
|
|
|
|
|
} else {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
// brutality mode :/
|
|
|
|
|
opcache_reset();
|
|
|
|
|
require 'phar://spip_loader.phar/vendor/autoload.php';
|
|
|
|
|
Debug::add('Reset opcache', 'Script reset opcache to start the Loader (really bad thing 😢)');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$bootstrap = new Spip_Loader_Phar_Bootstrap();
|
|
|
|
|
$bootstrap->init();
|
|
|
|
|
|
|
|
|
|
if (!http_response_code()) {
|
|
|
|
|
require 'phar://spip_loader.phar/bin/console.php';
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($debug) {
|
|
|
|
|
if (self::DEBUG) {
|
|
|
|
|
Debug::enable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function spip_loader_phar_path($path) {
|
|
|
|
|
Phar::webPhar('spip_loader.phar', null, null, ['svg' => 'image/svg+xml'], function ($incomming_path) {
|
|
|
|
|
$path = $incomming_path;
|
|
|
|
|
|
|
|
|
|
// Gestion des assets (spip_loader.php/?file=assets/...)
|
|
|
|
|
if (isset($_GET['file'])) {
|
|
|
|
|
return '/' . ltrim($_GET['file'], '/');
|
|
|
|
@ -63,12 +86,6 @@ try {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Phar::webPhar('spip_loader.phar', null, null, ['svg' => 'image/svg+xml'], function ($incomming_path) use ($debug) {
|
|
|
|
|
$path = spip_loader_phar_path($incomming_path);
|
|
|
|
|
|
|
|
|
|
Debug::add('incomming path', $incomming_path);
|
|
|
|
|
Debug::add('calculated path', $path);
|
|
|
|
|
|
|
|
|
@ -91,9 +108,9 @@ try {
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
// @note use \Throwable when PHP 7+
|
|
|
|
|
if ($debug) { echo $e->getMessage(); } else { throw $e; };
|
|
|
|
|
if (Spip_Loader_Phar_Bootstrap::DEBUG) { echo $e->getMessage(); } else { throw $e; };
|
|
|
|
|
} catch (\Error $e) {
|
|
|
|
|
if ($debug) { echo $e->getMessage(); } else { throw $e; };
|
|
|
|
|
if (Spip_Loader_Phar_Bootstrap::DEBUG) { echo $e->getMessage(); } else { throw $e; };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__HALT_COMPILER();
|
|
|
|
|