-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. added phar to use without composer
2. fixed slashes inside map/bean keys
- Loading branch information
TeleMessage
committed
Aug 31, 2015
1 parent
43a564a
commit 7ec1bdc
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
require "vendor/autoload.php"; | ||
|
||
$composer = \grinfeld\phpjsonable\parsers\json\Json::decode(new \grinfeld\phpjsonable\utils\streams\StringInputStream(file_get_contents("composer.json"))); | ||
$name = preg_replace("/[\\/]/", "_", $composer["name"]); | ||
$sources = array(); | ||
if (isset($composer["autoload"]) && isset($composer["autoload"]["psr-4"])) { | ||
$sources = $composer["autoload"]["psr-4"]; | ||
} | ||
$pharName = $name . '.phar'; | ||
$phar = new Phar($pharName); | ||
$dirName = dirname(__FILE__); | ||
while(list($suffix, $src) = each($sources)) { | ||
$dir = $dirName . "\\" . $src; | ||
$rp = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); | ||
foreach ($rp as $file) { | ||
if ($file->isFile() && $file->getFilename() != ".." && $file->getFilename() != ".") { | ||
$pathBefore = substr($file->getPath(), 0, strlen($dir)); | ||
$pathAfter = substr($file->getPath(), strlen($dir) + 1); | ||
$pathTo = "\\" . $suffix . ($pathAfter !== false ? ($pathAfter . "\\") : "") . $file->getFilename(); | ||
$phar->addFromString($pathTo, file_get_contents($file->getPath() . "/" . $file->getFilename())); | ||
} | ||
} | ||
} | ||
|
||
if (isset($composer["require"])) { | ||
while(list($library, $ver) = each($composer["require"])) { | ||
if (file_exists($dirName . "\\vendor\\" . $library)) { | ||
$dir = $dirName . "\\vendor\\" . $library; | ||
$rp = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); | ||
} | ||
foreach ($rp as $file) { | ||
if ($file->isFile() && $file->getFilename() != ".." && $file->getFilename() != ".") { | ||
$pathBefore = substr($file->getPath(), 0, strlen($dir)); | ||
$pathAfter = substr($file->getPath(), strlen($dir) + 1); | ||
$pathTo = "\\" . $suffix . ($pathAfter !== false ? ($pathAfter . "\\") : "") . $file->getFilename(); | ||
$phar->addFromString($pathTo, file_get_contents($file->getPath() . "/" . $file->getFilename())); | ||
} | ||
} | ||
} | ||
} | ||
|
||
$stubSource = "<?php\r\n" . | ||
"class TMLoader {\r\n" . | ||
" public static function get() {\r\n" . | ||
" spl_autoload_register(function (\$class) {\r\n" . | ||
" \$fileName = \"phar://$pharName/\" . \$class . \".php\";\r\n" . | ||
" if (file_exists(\$fileName)) {\r\n" . | ||
" include_once (\$fileName);\r\n" . | ||
" }\r\n" . | ||
" })\r\n;" . | ||
" }\r\n" . | ||
"}"; | ||
$phar->addFromString("TMLoader.php", $stubSource); | ||
$phar->setStub($phar->createDefaultStub('TMLoader.php')); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters