Skip to content

Commit

Permalink
1. added phar to use without composer
Browse files Browse the repository at this point in the history
2. fixed slashes inside map/bean keys
  • Loading branch information
TeleMessage committed Aug 31, 2015
1 parent 43a564a commit 7ec1bdc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
55 changes: 55 additions & 0 deletions createphar.php
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 added grinfeld_phpjsonable.phar
Binary file not shown.
6 changes: 5 additions & 1 deletion src/parsers/json/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,15 @@ private function parseMap(&$m) {
} else if ($c != self::SPACE_CHAR && $c != self::TAB_CHAR && $c != "\r" && $c != "\n") {
$sb = "";
// searching key
$prevC = $c;
do {
if ($c === false)
throw new \Exception("Reached end of stream - un-parsed data");
if ($c != self::ELEM_DELIM && $c != "\r" && $c != "\n")
if ($prevC == "\\" && $c == "\\") {

} else if ($c != self::ELEM_DELIM && $c != "\r" && $c != "\n")
$sb = $sb . $c;
$prevC = $c;
} while (false !== ($c = $this->in->nextChar()) && $c != self::VALUE_DELIM);
$key = trim($sb);
if (self::startsWith($key, self::CHAR_CHAR) || self::startsWith($key, self::STRING_CHAR))
Expand Down

0 comments on commit 7ec1bdc

Please sign in to comment.