Path: blob/main/databases/adminer/files/makephar.php
18157 views
<?php1/***********************************************************2*3* Merges adminer.php and it's plugins to a phar archive4*5***********************************************************/67$phar = new Phar(8$tmpFile = __DIR__ . '/adminer_' . bin2hex(random_bytes(8)) . '.phar',90,10'adminer.phar'11);1213$stub = <<<STUB14<?php15/******************************************************************************16*17* All Adminer plugins are now included in this18* FreeBSD ports edition, no need to download19* them separately.20* https://www.adminer.org/en/plugins/21*22* copyright Paavo-Einari Kaipila (FreeBSD ports edition)23* copyright Jakub Vrana (original Adminer)24*25* Licensed under the Apache License, Version 2.0 (the "License");26* you may not use this file except in compliance with the License.27* You may obtain a copy of the License at28*29* http://www.apache.org/licenses/LICENSE-2.030*31* Unless required by applicable law or agreed to in writing, software32* distributed under the License is distributed on an "AS IS" BASIS,33* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.34* See the License for the specific language governing permissions and35* limitations under the License.36*37******************************************************************************/38if (file_exists(\$adminerObjectFile = __DIR__ . '/adminer-object.php'))39{40require \$adminerObjectFile;41}42Phar::mapPhar('adminer.phar');43define('ADMINER_PLUGIN_CLASSMAP', json_decode('%s', true));44require 'phar://adminer.phar/autoload.php';45__HALT_COMPILER();46STUB;4748$classMap = [];49$plugins = [];5051foreach(new DirectoryIterator(__DIR__ . '/plugins') as $file)52{53if ($file->isFile())54{55$contents = php_strip_whitespace($file->getRealPath());56$pharFile = 'adminer-plugins/' . $file->getFileName();57$plugins[$pharFile] = $contents;58if (preg_match('/class\s(A[a-zA-Z]+)\sextends\sAdminer/', $contents, $m))59{60$classMap[$m[1]] = $file->getFileName();61}62}63}6465$phar->setStub(66sprintf(67$stub,68json_encode($classMap, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)69)70);7172$autoLoader = <<<LOADER73<?php74spl_autoload_register(function(\$class)75{76if (isset(ADMINER_PLUGIN_CLASSMAP[\$class]))77{78require __DIR__ . '/adminer-plugins/' . ADMINER_PLUGIN_CLASSMAP[\$class];79return true;80}81});82require __DIR__ . '/adminer.php';83LOADER;8485$phar->addFromString(86'autoload.php',87$autoLoader88);8990foreach($plugins as $file => $contents)91{92$phar->addFromString(93$file,94$contents95);96}9798$phar->addFromString(99'adminer.php',100php_strip_whitespace(__DIR__ . '/adminer.php'),101);102103rename($tmpFile, __DIR__ . '/index.php');104105106