php-hotfix/makephar
2016-07-21 03:08:06 +02:00

1244 lines
33 KiB
Plaintext
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env php
<?php define('PHAR', true);define('PHAR_BUILD_DATE', '2016-07-21');define('PHAR_BUILD_TIME', 1469063229);define('VERSION', '0.1');?>
<?php $_deps=json_decode('[]');
// dependency check
if (!empty($_deps)) {
$exts = get_loaded_extensions();
$missing = [];
foreach ($_deps as $dep=>$version) {
if (strpos("ext-",$dep) !== 0)
continue;
$dep = str_replace("ext-","",$dep);
if (!in_array($dep, $exts)) {
$missing[] = $dep;
}
}
if (count($missing)>0) {
fprintf(STDERR, "Error: Required extensions are missing.\n - ".join("\n - ",$missing)."\n");
exit(1);
}
}
?>
<?php
$web = 'index.php';
if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
Phar::interceptFileFuncs();
set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
Phar::webPhar(null, $web);
include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
return;
}
if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
Extract_Phar::go(true);
$mimes = array(
'phps' => 2,
'c' => 'text/plain',
'cc' => 'text/plain',
'cpp' => 'text/plain',
'c++' => 'text/plain',
'dtd' => 'text/plain',
'h' => 'text/plain',
'log' => 'text/plain',
'rng' => 'text/plain',
'txt' => 'text/plain',
'xsd' => 'text/plain',
'php' => 1,
'inc' => 1,
'avi' => 'video/avi',
'bmp' => 'image/bmp',
'css' => 'text/css',
'gif' => 'image/gif',
'htm' => 'text/html',
'html' => 'text/html',
'htmls' => 'text/html',
'ico' => 'image/x-ico',
'jpe' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'js' => 'application/x-javascript',
'midi' => 'audio/midi',
'mid' => 'audio/midi',
'mod' => 'audio/mod',
'mov' => 'movie/quicktime',
'mp3' => 'audio/mp3',
'mpg' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'pdf' => 'application/pdf',
'png' => 'image/png',
'swf' => 'application/shockwave-flash',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'wav' => 'audio/wav',
'xbm' => 'image/xbm',
'xml' => 'text/xml',
);
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$basename = basename(__FILE__);
if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
chdir(Extract_Phar::$temp);
include $web;
return;
}
$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
if (!$pt || $pt == '/') {
$pt = $web;
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
exit;
}
$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
header('HTTP/1.0 404 Not Found');
echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
exit;
}
$b = pathinfo($a);
if (!isset($b['extension'])) {
header('Content-Type: text/plain');
header('Content-Length: ' . filesize($a));
readfile($a);
exit;
}
if (isset($mimes[$b['extension']])) {
if ($mimes[$b['extension']] === 1) {
include $a;
exit;
}
if ($mimes[$b['extension']] === 2) {
highlight_file($a);
exit;
}
header('Content-Type: ' .$mimes[$b['extension']]);
header('Content-Length: ' . filesize($a));
readfile($a);
exit;
}
}
class Extract_Phar
{
static $temp;
static $origdir;
const GZ = 0x1000;
const BZ2 = 0x2000;
const MASK = 0x3000;
const START = 'bin/makephar.php';
const LEN = 6692;
static function go($return = false)
{
$fp = fopen(__FILE__, 'rb');
fseek($fp, self::LEN);
$L = unpack('V', $a = (binary)fread($fp, 4));
$m = (binary)'';
do {
$read = 8192;
if ($L[1] - strlen($m) < 8192) {
$read = $L[1] - strlen($m);
}
$last = (binary)fread($fp, $read);
$m .= $last;
} while (strlen($last) && strlen($m) < $L[1]);
if (strlen($m) < $L[1]) {
die('ERROR: manifest length read was "' .
strlen($m) .'" should be "' .
$L[1] . '"');
}
$info = self::_unpack($m);
$f = $info['c'];
if ($f & self::GZ) {
if (!function_exists('gzinflate')) {
die('Error: zlib extension is not enabled -' .
' gzinflate() function needed for zlib-compressed .phars');
}
}
if ($f & self::BZ2) {
if (!function_exists('bzdecompress')) {
die('Error: bzip2 extension is not enabled -' .
' bzdecompress() function needed for bz2-compressed .phars');
}
}
$temp = self::tmpdir();
if (!$temp || !is_writable($temp)) {
$sessionpath = session_save_path();
if (strpos ($sessionpath, ";") !== false)
$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
die('Could not locate temporary directory to extract phar');
}
$temp = $sessionpath;
}
$temp .= '/pharextract/'.basename(__FILE__, '.phar');
self::$temp = $temp;
self::$origdir = getcwd();
@mkdir($temp, 0777, true);
$temp = realpath($temp);
if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
self::_removeTmpFiles($temp, getcwd());
@mkdir($temp, 0777, true);
@file_put_contents($temp . '/' . md5_file(__FILE__), '');
foreach ($info['m'] as $path => $file) {
$a = !file_exists(dirname($temp . '/' . $path));
@mkdir(dirname($temp . '/' . $path), 0777, true);
clearstatcache();
if ($path[strlen($path) - 1] == '/') {
@mkdir($temp . '/' . $path, 0777);
} else {
file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
@chmod($temp . '/' . $path, 0666);
}
}
}
chdir($temp);
if (!$return) {
include self::START;
}
}
static function tmpdir()
{
if (strpos(PHP_OS, 'WIN') !== false) {
if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
return $var;
}
if (is_dir('/temp') || mkdir('/temp')) {
return realpath('/temp');
}
return false;
}
if ($var = getenv('TMPDIR')) {
return $var;
}
return realpath('/tmp');
}
static function _unpack($m)
{
$info = unpack('V', substr($m, 0, 4));
$l = unpack('V', substr($m, 10, 4));
$m = substr($m, 14 + $l[1]);
$s = unpack('V', substr($m, 0, 4));
$o = 0;
$start = 4 + $s[1];
$ret['c'] = 0;
for ($i = 0; $i < $info[1]; $i++) {
$len = unpack('V', substr($m, $start, 4));
$start += 4;
$savepath = substr($m, $start, $len[1]);
$start += $len[1];
$ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
& 0xffffffff);
$ret['m'][$savepath][7] = $o;
$o += $ret['m'][$savepath][2];
$start += 24 + $ret['m'][$savepath][5];
$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
}
return $ret;
}
static function extractFile($path, $entry, $fp)
{
$data = '';
$c = $entry[2];
while ($c) {
if ($c < 8192) {
$data .= @fread($fp, $c);
$c = 0;
} else {
$c -= 8192;
$data .= @fread($fp, 8192);
}
}
if ($entry[4] & self::GZ) {
$data = gzinflate($data);
} elseif ($entry[4] & self::BZ2) {
$data = bzdecompress($data);
}
if (strlen($data) != $entry[0]) {
die("Invalid internal .phar file (size error " . strlen($data) . " != " .
$stat[7] . ")");
}
if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
die("Invalid internal .phar file (checksum error)");
}
return $data;
}
static function _removeTmpFiles($temp, $origdir)
{
chdir($temp);
foreach (glob('*') as $f) {
if (file_exists($f)) {
is_dir($f) ? @rmdir($f) : @unlink($f);
if (file_exists($f) && is_dir($f)) {
self::_removeTmpFiles($f, getcwd());
}
}
}
@rmdir($temp);
clearstatcache();
chdir($origdir);
}
}
Extract_Phar::go();
__HALT_COMPILER(); ?>
<EFBFBD>

bin/build.php:= <20>W:<00>V<EFBFBD>$<24>bin/makephar.php<68>= <20>W<EFBFBD><00><>i<EFBFBD><69>src/BuildProps.phpD= <20>WD5 src/DependencyValidator.phpL= <20>WL<48><C683>src/PharBuilder.php<68>= <20>W<EFBFBD>&<26><><EFBFBD> src/stub.php<68>= <20>W<EFBFBD>@`P<><50>vendor/autoload.php<68>= <20>W<EFBFBD><00><><00><>vendor/composer/ClassLoader.php<68>0= <20>W<EFBFBD>0<00><><EFBFBD>]<5D>vendor/composer/LICENSE3= <20>W3<00><1E><><EFBFBD>%vendor/composer/autoload_classmap.php<68>= <20>W<EFBFBD><00><>b<07>'vendor/composer/autoload_namespaces.php<68>= <20>W<EFBFBD>t<>!vendor/composer/autoload_psr4.php<68>= <20>W<EFBFBD>w<><77><1E>!vendor/composer/autoload_real.php= <20>WR<><52><EFBFBD><EFBFBD><?php
require_once __DIR__."/../vendor/autoload.php";
use NoccyLabs\MakePhar\PharBuilder;
$builder = new PharBuilder();
$builder->setOutput("makephar");
$builder->addInput([
"bin",
"src",
"vendor",
]);
$builder->setStub("bin/makephar.php");
$builder->setProp('VERSION', '0.1');
$builder->build();
<?php
require_once __DIR__."/../vendor/autoload.php";
use NoccyLabs\MakePhar\PharBuilder;
$wd = getcwd();
if (!defined('PHAR')) {
echo "\e[41;37mError: \e[1mThis program can not be executed from source, please use the build tools to make a phar.\e[0m\n";
exit(1);
}
function showUsage() {
global $argv;
printf("Usage: %s [-hvn] [-o file]\n", basename($argv[0]));
printf("Options: -h,--help Show this help\n");
printf(" -v Verbose operation\n");
printf(" -m Write a Makefile\n");
printf(" -n,--init Create a new build configuration\n");
printf(" -o,--output Override output file\n");
printf(" -c,--config Specify alternate makephar.conf\n");
printf(" -z,-zz,-zzz Compress the phar (more, even more)\n");
printf(" -q Quiet mode, only error output\n");
}
function createBuildConfig() {
if (file_exists(getcwd()."/makephar.conf")) {
echo "\e[41;37mError: \e[1mA makephar.conf already exists.\e[0m\n";
exit(1);
}
$config = [
"output" => "outfile",
"include" => [ "src", "vendor" ],
"stub" => "boot.php",
"options" => [ "chmod" => "0777", "compress" => 0 ]
];
file_put_contents("makephar.conf", json_encode($config, JSON_PRETTY_PRINT));
echo "Created makephar.conf\n";
}
function createMakefile() {
if (file_exists(getcwd()."/Makefile")) {
echo "\e[41;37mError: \e[1mA Makefile already exists.\e[0m\n";
exit(1);
}
$src = ".phony: phar\n";
$src.= "phar:\n\tmakephar -c makephar.conf\n";
file_put_contents("Makefile", $src);
echo "Created Makefile\n";
}
function buildFromConfig(array $config=[]) {
global $argv;
$configFile = $config['config'];
if (!file_exists($configFile)) {
echo "\e[41;37mError: \e[1mConfiguration file ({$configFile}) not found, use '".basename($argv[0])." --init' to create one\e[0m\n";
exit(1);
}
$config = array_merge(
[
"compress" => 0,
],
json_decode(file_get_contents($configFile), true),
$config
);
$builder = new PharBuilder();
$builder->setCompression((int)$config['compress']);
$builder->setOutput($config['output']);
$builder->addInput($config['include']);
$builder->setStub($config['stub']);
if ($config['quiet']) ob_start();
printf("MakePhar %s (%s), (c) 2016, NoccyLabs.\nDistributed under GNU GPL 3.0\n\n", VERSION, PHAR_BUILD_DATE);
$builder->build();
if ($config['quiet']) ob_end_clear();
}
$opts = getopt("hvno:c:mzq", ["help", "output", "init"]);
$noBuild = false;
$compress = 0;
$quiet = false;
$config = getcwd()."/makephar.conf";
foreach ($opts as $opt=>$value) {
switch ($opt) {
case 'c':
$config = $value;
if ($config[0] == "/") break;
$config = getcwd()."/".$config;
break;
case 'h':
case 'help':
showUsage();
exit(0);
case 'n':
case 'init':
createBuildConfig();
$noBuild = true;
break;
case 'm':
createMakefile();
$noBuild = true;
break;
case 'z':
$compress = count((array)$value);
break;
case 'q':
$quiet = true;
return;
default:
printf("Unrecognized argument: %s\n", $opt);
exit(2);
}
}
if ($noBuild) {
exit(0);
}
$opts = [
'config' => $config
];
if ($compress > 0) {
$opts['compress'] = $compress;
}
$opts['quiet'] = $quiet;
buildFromConfig($opts);
<?php
namespace NoccyLabs\MakePhar;
class BuildProps
{
protected $props = [];
public function setProp($name, $value)
{
$this->props[$name] = $value;
}
public function setProps(array $props)
{
$this->props = array_merge(
$this->props,
$props
);
}
public function __toString()
{
$src = null;
foreach ($this->props as $key=>$value) {
$src.= sprintf("define('%s', %s);", $key, var_export($value,true));
}
return "<?php ".$src."?>";
}
}
<?php
namespace NoccyLabs\MakePhar;
class DependencyValidator
{
protected $dependencies = [];
public function __construct()
{
}
public function getDependencies()
{
return $this->dependencies;
}
public function scanFromComposer()
{
if (!file_exists(getcwd()."/composer.json")) {
throw new \Exception("No composer.json found");
}
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(getcwd()."/vendor"));
$d = function ($file) {
$j = json_decode(file_get_contents(getcwd()."/composer.json"));
if (!empty($j->require)) {
return (array)($j->require);
}
return [];
};
$reqs = $d(getcwd().'/composer.json');
foreach ($it as $file) {
if ($file->getBasename() != "composer.json")
continue;
$reqs = array_merge(
$reqs,
$d($file->getPathname())
);
}
$this->dependencies = $reqs;
}
}
<?php
namespace NoccyLabs\MakePhar;
use Phar;
class PharBuilder
{
protected $output;
protected $input = [];
protected $stub;
protected $options = [
"verbose" => false
];
protected $props;
protected $compression = 0;
public function __construct()
{
$this->props = new BuildProps();
$this->props->setProps([
'PHAR' => true,
'PHAR_BUILD_DATE' => date('Y-m-d'),
'PHAR_BUILD_TIME' => time()
]);
}
public function setOutput($output)
{
$this->output = $output;
}
public function addInput($input)
{
$this->input = array_merge(
$this->input,
(array)$input
);
}
public function setProp($name, $value)
{
$this->props->setProp($name, $value);
}
public function setStub($stub)
{
$this->stub = $stub;
}
public function setCompression($level)
{
$this->compression = max(min($level, 3), 0);
}
public function build()
{
$this->logTask("Checking extension dependencies...");
$validator = new DependencyValidator();
try {
$validator->scanFromComposer();
} catch (\Exception $e) {}
$deps = $validator->getDependencies();
$validatorStub = "<?php \$_deps=json_decode('".json_encode($deps)."');\n".file_get_contents(__DIR__."/stub.php")." ?>";
$this->logTask("Creating phar archive...");
$temp = "/tmp/".uniqid().".phar";
$phar = new Phar($temp);
$this->logTask("Locating files to include...");
$fileobjs = $this->findFiles();
$fileobjs = array_combine($fileobjs, $fileobjs);
$this->logTask("Adding ".count($fileobjs)." files to archive");
if ($this->options['verbose']) {
foreach ($fileobjs as $file) {
$this->debug("{$file}");
}
}
$phar->buildFromIterator(
new \ArrayIterator($fileobjs)
);
$this->logTask("Creating phar stub from {$this->stub}");
$stub = $phar->createDefaultStub($this->stub);
$stub = "#!/usr/bin/env php \n".
$this->props."\n".
$validatorStub."\n".
$stub;
$phar->setStub($stub);
$phar->stopBuffering();
unset($phar);
$this->logTask("Generated size: ".round(filesize($temp)/1024,1)."KB");
if ($this->compression >= 3) {
$gzdata = gzencode(file_get_contents($temp),9);
$stub = "#!/bin/sh\n".
"PHAR=/tmp/\$(basename \$0).phar\n".
"tail -n+5 \$0 | gzip -d - > \$PHAR\n".
"php \$PHAR \$@; exit\n";
$packed = $stub.$gzdata;
file_put_contents($temp, $packed);
$this->logTask("Size after compression: ".round(strlen($packed)/1024,1)."KB");
}
if (file_exists($this->output)) { unlink($this->output); }
rename($temp, $this->output);
chmod($this->output, 0777);
}
protected function findFiles()
{
$fileobjs = [];
foreach ($this->input as $path) {
if (is_dir($path)) {
$it = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator(
$path
)
);
foreach ($it as $object) {
if ($object->isDir()) { continue; }
$fileobjs[] = $object->getPathname();
}
} elseif (file_exists($path)) {
$fileobjs[] = $path;
} elseif (($objects = @glob($path))) {
foreach ($objects as $path) {
$fileobjs[] = $path;
}
} else {
throw new \RuntimeException("Object does not exist: ".$path);
}
}
return $fileobjs;
}
protected function logTask($msg)
{
printf("\e[32m[\e[1m*\e[21m] \e[0m%s\n", $msg);
}
protected function debug($msg)
{
printf(" \e[33m-\e[1m-\e[21m- \e[0m%s\n", $msg);
}
}
// dependency check
if (!empty($_deps)) {
$exts = get_loaded_extensions();
$missing = [];
foreach ($_deps as $dep=>$version) {
if (strpos("ext-",$dep) !== 0)
continue;
$dep = str_replace("ext-","",$dep);
if (!in_array($dep, $exts)) {
$missing[] = $dep;
}
}
if (count($missing)>0) {
fprintf(STDERR, "Error: Required extensions are missing.\n - ".join("\n - ",$missing)."\n");
exit(1);
}
}
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit8dc0c0276fbdca4247ba62fa3df9b2ad::getLoader();
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see http://www.php-fig.org/psr/psr-0/
* @see http://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative) {
return false;
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if ($file === null && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if ($file === null) {
// Remember that this class does not exist.
return $this->classMap[$class] = false;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}
Copyright (c) 2016 Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'NoccyLabs\\MakePhar\\' => array($baseDir . '/src'),
);
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit8dc0c0276fbdca4247ba62fa3df9b2ad
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit8dc0c0276fbdca4247ba62fa3df9b2ad', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit8dc0c0276fbdca4247ba62fa3df9b2ad', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register(true);
return $loader;
}
}
<EFBFBD><EFBFBD>*o<><6F>jvZ<76>#<23><1B><>Y6VGBMB