Skip to content

Commit cb97622

Browse files
committed
Maintenance release.
Fixed XML, basic support for now; Re-enabled and modernized resources compilation! Removed undocumented assignment detection; Fixes, anonymous classes, etc
1 parent 8562517 commit cb97622

34 files changed

+3378
-739
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/vendor
55
composer.lock
66
package-lock.json
7+
*.map

Makefile

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
11
# `cd .` is because it sometimes solves https://github.com/docker/compose/issues/7899
2-
DOCKER_COMPOSE = cd . && docker compose
3-
2+
DOCKER = cd . && DOCKER_UID=$(shell id -u) DOCKER_GID=$(shell id -g) docker compose
43

54
console:
6-
$(DOCKER_COMPOSE) run php bash
5+
$(DOCKER) run php bash
76

87

98
sh:
109
make console
1110

1211

1312
build:
14-
$(DOCKER_COMPOSE) up -d
13+
$(DOCKER) up -d
1514
make test
16-
$(DOCKER_COMPOSE) run php composer build # see composer.json -> "scripts" section
15+
$(DOCKER) run php composer build # see composer.json -> "scripts" section
1716

1817

1918
test:
20-
$(DOCKER_COMPOSE) run php pest
19+
$(DOCKER) run php pest
2120

2221

2322
update-test-snapshots:
24-
$(DOCKER_COMPOSE) run php pest -d --update-snapshots
23+
$(DOCKER) run php pest -d --update-snapshots
24+
25+
26+
27+
nuke-docker:
28+
@# Help: Nuclear option to force-remove all docker images, volumes and containers
29+
-$(DOCKER) down --volumes
30+
-$(DOCKER) rm --force --stop --volumes
31+
-docker kill $$(docker ps -q)
32+
-docker volume rm $$(docker volume ls -q)
33+
-docker rmi --force $$(docker images -a -q)
34+
# the above is always enough, but the following command would do all of that
35+
# (and more!) and prune ALL cached images so they will have to be re-downloaded:
36+
# -docker system prune -f
37+
38+
39+
40+
down-for-good:
41+
@# Help: Stop docker and delete its volumes
42+
-$(DOCKER) rm --force --stop --volumes
43+
-$(DOCKER) down --volumes

Sage.php

+10-18
Original file line numberDiff line numberDiff line change
@@ -637,12 +637,6 @@ private static function _getCalleeInfo($trace)
637637
# spaces
638638
\x07*
639639
640-
# check if output is assigned to a variable (group 2) todo: does not detect concat
641-
(
642-
\\$[a-z0-9_]+ # variable
643-
\x07*\\.?=\x07* # assignment
644-
)?
645-
646640
# possibly a namespace symbol
647641
\\\\?
648642
@@ -665,20 +659,15 @@ private static function _getCalleeInfo($trace)
665659
);
666660

667661
$modifiers = end($matches[1]);
668-
$assignment = end($matches[2]);
669-
$callToSage = end($matches[3]);
670-
$bracket = end($matches[4]);
662+
$callToSage = end($matches[2]);
663+
$bracket = end($matches[3]);
671664

672665
if (empty($callToSage)) {
673666
// if a wrapper is misconfigured, don't display the whole file as variable name
674667
return array(array(), $modifiers, $callee, $previousCaller, $miniTrace);
675668
}
676669

677-
$modifiers = $modifiers[0];
678-
if ($assignment[1] !== -1) {
679-
$modifiers .= '@';
680-
}
681-
670+
$modifiers = $modifiers[0];
682671
$paramsString = preg_replace("[\x07+]", ' ', substr($source, $bracket[1] + 1));
683672
// we now have a string like this:
684673
// <parameters passed>); <the rest of the last read line>
@@ -690,22 +679,25 @@ private static function _getCalleeInfo($trace)
690679
$i = 0;
691680
$inBrackets = 0;
692681
$openedBrackets = array();
682+
$bracketPairs = array('(' => ')', '[' => ']', '{' => '}');
693683

694684
while ($i < $c) {
695685
$letter = $paramsString[$i];
696686

697687
if (! $inString) {
698688
if ($letter === '\'' || $letter === '"') {
699689
$inString = $letter;
700-
} elseif ($letter === '(' || $letter === '[') {
690+
} elseif ($letter === '(' || $letter === '[' || $letter === '{') {
701691
$inBrackets++;
702692
$openedBrackets[] = $openedBracket = $letter;
703-
$closingBracket = $openedBracket === '(' ? ')' : ']';
693+
$closingBracket = $bracketPairs[$letter];
704694
} elseif ($inBrackets && $letter === $closingBracket) {
705695
$inBrackets--;
706696
array_pop($openedBrackets);
707-
$openedBracket = end($openedBrackets);
708-
$closingBracket = $openedBracket === '(' ? ')' : ']';
697+
$openedBracket = end($openedBrackets);
698+
if ($openedBracket) {
699+
$closingBracket = $bracketPairs[$openedBracket];
700+
}
709701
} elseif (! $inBrackets && $letter === ')') {
710702
$paramsString = substr($paramsString, 0, $i);
711703
break;

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
"post-install-cmd": "@post-update-cmd",
4242
"build": [
4343
"@post-update-cmd",
44-
"@build:js",
44+
"@build:resources",
4545
"@build:php"
4646
],
4747
"build:php": "php .github/build/build.php",
48-
"build:js": "npm run build:js"
48+
"build:resources": "npm run build"
4949
}
5050
}

docker-compose.yml

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
services:
2-
# php53:
3-
# build: docker/php53
4-
# working_dir: /var/www/
5-
# volumes:
6-
# - ./:/var/www
7-
# extra_hosts:
8-
# - "host.docker.internal:host-gateway" # docker on mac lacks `host-gateway`
9-
# environment:
10-
# PHP_IDE_CONFIG: serverName=localhost # For Xdebug to work: PhpStorm ⇛ Settings ⇛ PHP ⇛ Servers ⇛ Name
2+
# php53:
3+
# build: docker/php53
4+
# working_dir: /var/www/
5+
# volumes:
6+
# - ./:/var/www
7+
# extra_hosts:
8+
# - "host.docker.internal:host-gateway" # docker on mac lacks `host-gateway`
9+
# environment:
10+
# PHP_IDE_CONFIG: serverName=localhost # For Xdebug to work: PhpStorm ⇛ Settings ⇛ PHP ⇛ Servers ⇛ Name
1111
php:
12-
build: docker
12+
build:
13+
context: docker
14+
args:
15+
- DOCKER_UID
1316
working_dir: /var/www/
1417
volumes:
1518
- ./:/var/www
1619
extra_hosts:
1720
- "host.docker.internal:host-gateway" # docker on mac lacks `host-gateway`
21+
user:
22+
"${DOCKER_UID:-1000}:${DOCKER_GID:-1000}"
1823
environment:
19-
PHP_IDE_CONFIG: serverName=localhost # For Xdebug to work: PhpStorm ⇛ Settings ⇛ PHP ⇛ Servers ⇛ Name
24+
PHP_IDE_CONFIG: serverName=localhost # For Xdebug to work: PhpStorm ⇛ Settings ⇛ PHP ⇛ Servers ⇛ Name

docker/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
FROM node:latest AS node
22
FROM php:fpm
33

4+
ARG DOCKER_UID
5+
46
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
57
COPY --from=node /usr/local/bin/node /usr/local/bin/node
68
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
@@ -18,3 +20,8 @@ RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/
1820

1921
# disable phar readonly
2022
RUN echo "phar.readonly = Off" >> /usr/local/etc/php/conf.d/php.enable-phar.ini
23+
24+
25+
RUN useradd -u ${DOCKER_UID} -m the-whale; \
26+
useradd -u ${DOCKER_UID} -m the-whale; \
27+
usermod -G www-data,the-whale,root,adm the-whale

inc/SageParser.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ private static function _parse_array(&$variable, SageVariableData $variableData)
276276

277277
if ($variableData->size > 1 && ($arrayKeys = self::_isArrayTabular($variable)) !== false) {
278278
// tabular array parse
279-
$firstRow = true;
280-
$extendedValue = '<table class="_sage-report"><thead>';
279+
$firstRow = true;
280+
$extendedValue = '<table class="_sage-report"><thead>';
281281

282282
foreach ($variable as $rowIndex => & $row) {
283283
// display strings in their full length
@@ -648,7 +648,11 @@ public static function alternativesParse($originalVar, $alternativesArray)
648648
$originalVar[self::$_marker] = true;
649649
}
650650

651-
self::_parse_array($alternativesArray, $varData);
651+
if (is_array($alternativesArray)) {
652+
self::_parse_array($alternativesArray, $varData);
653+
} else {
654+
self::_parse_object($alternativesArray, $varData);
655+
}
652656

653657
return $varData->extendedValue;
654658
}

inc/SageVariableData.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function addTabToView($originalVariable, $tabName, $value)
3535
{
3636
if (is_array($value)) {
3737
if (! (reset($value) instanceof self)) {
38-
// concert to SageVariableData[]
38+
// convert to SageVariableData[]
3939
$value = SageParser::alternativesParse($originalVariable, $value);
4040
}
4141
} elseif (is_string($value)) {

package.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
{
22
"private": true,
33
"devDependencies": {
4+
"npm-watch": "^0",
5+
"sass": "^1",
46
"uglify-js": "^3"
57
},
8+
"watch": {
9+
"compile-js": "resources/base.js",
10+
"compile-css": "resources/css/*.scss"
11+
},
612
"scripts": {
7-
"build:js": "uglifyjs resources/base.js -cm --toplevel --mangle-props --warn > resources/compiled/sage.js"
13+
"sass-dev": "sass --watch --update --no-source-map --style=expanded resources/css/themes/:resources/compiled/",
14+
"sass-dev-c": "sass --watch --update --no-source-map --style=compressed resources/css/themes/:resources/compiled/",
15+
"compile-css": "sass --style=compressed --no-source-map resources/css/themes/:resources/compiled/",
16+
"compile-js": "uglifyjs resources/js/base.js -cm --toplevel --mangle-props -o resources/compiled/sage.js",
17+
"watch": "npm-watch",
18+
"build": "npm run compile-js; npm run compile-css"
819
}
920
}

parsers/SageParsersXml.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,28 @@ class SageParsersXml extends SageParser
88
{
99
protected static function parse(&$variable, $varData)
1010
{
11-
try {
12-
if (! SageHelper::isRichMode()) {
13-
return false;
14-
}
11+
if (! SageHelper::isRichMode()) {
12+
return false;
13+
}
1514

16-
if (is_string($variable) && substr($variable, 0, 5) === '<?xml') {
15+
if (is_string($variable) && substr($variable, 0, 5) === '<?xml') {
16+
try {
1717
$e = libxml_use_internal_errors(true);
1818
$xml = simplexml_load_string($variable);
1919
libxml_use_internal_errors($e);
20-
if (empty($xml)) {
21-
return false;
22-
}
23-
} else {
20+
} catch (Exception $e) {
2421
return false;
2522
}
26-
} catch (Exception $e) {
23+
24+
if (empty($xml)) {
25+
return false;
26+
}
27+
} else {
2728
return false;
2829
}
2930

30-
$varData->addTabToView($variable, 'XML', @date('Y-m-d H:i:s', $xml));
31+
// dd($xml);
32+
33+
$varData->addTabToView($variable, 'XML', SageParser::alternativesParse($variable, $xml));
3134
}
3235
}

0 commit comments

Comments
 (0)