Skip to content

Commit 7ec1bdc

Browse files
author
TeleMessage
committed
1. added phar to use without composer
2. fixed slashes inside map/bean keys
1 parent 43a564a commit 7ec1bdc

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

createphar.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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'));

grinfeld_phpjsonable.phar

74 KB
Binary file not shown.

src/parsers/json/Reader.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,15 @@ private function parseMap(&$m) {
221221
} else if ($c != self::SPACE_CHAR && $c != self::TAB_CHAR && $c != "\r" && $c != "\n") {
222222
$sb = "";
223223
// searching key
224+
$prevC = $c;
224225
do {
225226
if ($c === false)
226227
throw new \Exception("Reached end of stream - un-parsed data");
227-
if ($c != self::ELEM_DELIM && $c != "\r" && $c != "\n")
228+
if ($prevC == "\\" && $c == "\\") {
229+
230+
} else if ($c != self::ELEM_DELIM && $c != "\r" && $c != "\n")
228231
$sb = $sb . $c;
232+
$prevC = $c;
229233
} while (false !== ($c = $this->in->nextChar()) && $c != self::VALUE_DELIM);
230234
$key = trim($sb);
231235
if (self::startsWith($key, self::CHAR_CHAR) || self::startsWith($key, self::STRING_CHAR))

0 commit comments

Comments
 (0)