|
| 1 | +<?php |
| 2 | + require "vendor/autoload.php"; |
| 3 | + |
| 4 | + $composer = \grinfeld\phpjsonable\parsers\json\Json::decode(new \grinfeld\phpjsonable\utils\streams\StringInputStream(file_get_contents("composer.json"))); |
| 5 | + $name = preg_replace("/[\\/]/", "_", $composer["name"]); |
| 6 | + $sources = array(); |
| 7 | + if (isset($composer["autoload"]) && isset($composer["autoload"]["psr-4"])) { |
| 8 | + $sources = $composer["autoload"]["psr-4"]; |
| 9 | + } |
| 10 | + $pharName = $name . '.phar'; |
| 11 | + $phar = new Phar($pharName); |
| 12 | + $dirName = dirname(__FILE__); |
| 13 | + while(list($suffix, $src) = each($sources)) { |
| 14 | + $dir = $dirName . "\\" . $src; |
| 15 | + $rp = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); |
| 16 | + foreach ($rp as $file) { |
| 17 | + if ($file->isFile() && $file->getFilename() != ".." && $file->getFilename() != ".") { |
| 18 | + $pathBefore = substr($file->getPath(), 0, strlen($dir)); |
| 19 | + $pathAfter = substr($file->getPath(), strlen($dir) + 1); |
| 20 | + $pathTo = "\\" . $suffix . ($pathAfter !== false ? ($pathAfter . "\\") : "") . $file->getFilename(); |
| 21 | + $phar->addFromString($pathTo, file_get_contents($file->getPath() . "/" . $file->getFilename())); |
| 22 | + } |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + if (isset($composer["require"])) { |
| 27 | + while(list($library, $ver) = each($composer["require"])) { |
| 28 | + if (file_exists($dirName . "\\vendor\\" . $library)) { |
| 29 | + $dir = $dirName . "\\vendor\\" . $library; |
| 30 | + $rp = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); |
| 31 | + } |
| 32 | + foreach ($rp as $file) { |
| 33 | + if ($file->isFile() && $file->getFilename() != ".." && $file->getFilename() != ".") { |
| 34 | + $pathBefore = substr($file->getPath(), 0, strlen($dir)); |
| 35 | + $pathAfter = substr($file->getPath(), strlen($dir) + 1); |
| 36 | + $pathTo = "\\" . $suffix . ($pathAfter !== false ? ($pathAfter . "\\") : "") . $file->getFilename(); |
| 37 | + $phar->addFromString($pathTo, file_get_contents($file->getPath() . "/" . $file->getFilename())); |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + $stubSource = "<?php\r\n" . |
| 44 | + "class TMLoader {\r\n" . |
| 45 | + " public static function get() {\r\n" . |
| 46 | + " spl_autoload_register(function (\$class) {\r\n" . |
| 47 | + " \$fileName = \"phar://$pharName/\" . \$class . \".php\";\r\n" . |
| 48 | + " if (file_exists(\$fileName)) {\r\n" . |
| 49 | + " include_once (\$fileName);\r\n" . |
| 50 | + " }\r\n" . |
| 51 | + " })\r\n;" . |
| 52 | + " }\r\n" . |
| 53 | + "}"; |
| 54 | + $phar->addFromString("TMLoader.php", $stubSource); |
| 55 | + $phar->setStub($phar->createDefaultStub('TMLoader.php')); |
0 commit comments