Skip to content

Commit

Permalink
Maintenance release.
Browse files Browse the repository at this point in the history
Fixed XML, basic support for now;
Re-enabled and modernized resources compilation!
Removed undocumented assignment detection;
Fixes, anonymous classes, etc
  • Loading branch information
raveren committed Apr 2, 2023
1 parent 8562517 commit cb97622
Show file tree
Hide file tree
Showing 34 changed files with 3,378 additions and 739 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/vendor
composer.lock
package-lock.json
*.map
33 changes: 26 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
# `cd .` is because it sometimes solves https://github.com/docker/compose/issues/7899
DOCKER_COMPOSE = cd . && docker compose

DOCKER = cd . && DOCKER_UID=$(shell id -u) DOCKER_GID=$(shell id -g) docker compose

console:
$(DOCKER_COMPOSE) run php bash
$(DOCKER) run php bash


sh:
make console


build:
$(DOCKER_COMPOSE) up -d
$(DOCKER) up -d
make test
$(DOCKER_COMPOSE) run php composer build # see composer.json -> "scripts" section
$(DOCKER) run php composer build # see composer.json -> "scripts" section


test:
$(DOCKER_COMPOSE) run php pest
$(DOCKER) run php pest


update-test-snapshots:
$(DOCKER_COMPOSE) run php pest -d --update-snapshots
$(DOCKER) run php pest -d --update-snapshots



nuke-docker:
@# Help: Nuclear option to force-remove all docker images, volumes and containers
-$(DOCKER) down --volumes
-$(DOCKER) rm --force --stop --volumes
-docker kill $$(docker ps -q)
-docker volume rm $$(docker volume ls -q)
-docker rmi --force $$(docker images -a -q)
# the above is always enough, but the following command would do all of that
# (and more!) and prune ALL cached images so they will have to be re-downloaded:
# -docker system prune -f



down-for-good:
@# Help: Stop docker and delete its volumes
-$(DOCKER) rm --force --stop --volumes
-$(DOCKER) down --volumes
28 changes: 10 additions & 18 deletions Sage.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,6 @@ private static function _getCalleeInfo($trace)
# spaces
\x07*
# check if output is assigned to a variable (group 2) todo: does not detect concat
(
\\$[a-z0-9_]+ # variable
\x07*\\.?=\x07* # assignment
)?
# possibly a namespace symbol
\\\\?
Expand All @@ -665,20 +659,15 @@ private static function _getCalleeInfo($trace)
);

$modifiers = end($matches[1]);
$assignment = end($matches[2]);
$callToSage = end($matches[3]);
$bracket = end($matches[4]);
$callToSage = end($matches[2]);
$bracket = end($matches[3]);

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

$modifiers = $modifiers[0];
if ($assignment[1] !== -1) {
$modifiers .= '@';
}

$modifiers = $modifiers[0];
$paramsString = preg_replace("[\x07+]", ' ', substr($source, $bracket[1] + 1));
// we now have a string like this:
// <parameters passed>); <the rest of the last read line>
Expand All @@ -690,22 +679,25 @@ private static function _getCalleeInfo($trace)
$i = 0;
$inBrackets = 0;
$openedBrackets = array();
$bracketPairs = array('(' => ')', '[' => ']', '{' => '}');

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

if (! $inString) {
if ($letter === '\'' || $letter === '"') {
$inString = $letter;
} elseif ($letter === '(' || $letter === '[') {
} elseif ($letter === '(' || $letter === '[' || $letter === '{') {
$inBrackets++;
$openedBrackets[] = $openedBracket = $letter;
$closingBracket = $openedBracket === '(' ? ')' : ']';
$closingBracket = $bracketPairs[$letter];
} elseif ($inBrackets && $letter === $closingBracket) {
$inBrackets--;
array_pop($openedBrackets);
$openedBracket = end($openedBrackets);
$closingBracket = $openedBracket === '(' ? ')' : ']';
$openedBracket = end($openedBrackets);
if ($openedBracket) {
$closingBracket = $bracketPairs[$openedBracket];
}
} elseif (! $inBrackets && $letter === ')') {
$paramsString = substr($paramsString, 0, $i);
break;
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"post-install-cmd": "@post-update-cmd",
"build": [
"@post-update-cmd",
"@build:js",
"@build:resources",
"@build:php"
],
"build:php": "php .github/build/build.php",
"build:js": "npm run build:js"
"build:resources": "npm run build"
}
}
27 changes: 16 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
services:
# php53:
# build: docker/php53
# working_dir: /var/www/
# volumes:
# - ./:/var/www
# extra_hosts:
# - "host.docker.internal:host-gateway" # docker on mac lacks `host-gateway`
# environment:
# PHP_IDE_CONFIG: serverName=localhost # For Xdebug to work: PhpStorm ⇛ Settings ⇛ PHP ⇛ Servers ⇛ Name
# php53:
# build: docker/php53
# working_dir: /var/www/
# volumes:
# - ./:/var/www
# extra_hosts:
# - "host.docker.internal:host-gateway" # docker on mac lacks `host-gateway`
# environment:
# PHP_IDE_CONFIG: serverName=localhost # For Xdebug to work: PhpStorm ⇛ Settings ⇛ PHP ⇛ Servers ⇛ Name
php:
build: docker
build:
context: docker
args:
- DOCKER_UID
working_dir: /var/www/
volumes:
- ./:/var/www
extra_hosts:
- "host.docker.internal:host-gateway" # docker on mac lacks `host-gateway`
user:
"${DOCKER_UID:-1000}:${DOCKER_GID:-1000}"
environment:
PHP_IDE_CONFIG: serverName=localhost # For Xdebug to work: PhpStorm ⇛ Settings ⇛ PHP ⇛ Servers ⇛ Name
PHP_IDE_CONFIG: serverName=localhost # For Xdebug to work: PhpStorm ⇛ Settings ⇛ PHP ⇛ Servers ⇛ Name
7 changes: 7 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM node:latest AS node
FROM php:fpm

ARG DOCKER_UID

COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node /usr/local/bin/node /usr/local/bin/node
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
Expand All @@ -18,3 +20,8 @@ RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/

# disable phar readonly
RUN echo "phar.readonly = Off" >> /usr/local/etc/php/conf.d/php.enable-phar.ini


RUN useradd -u ${DOCKER_UID} -m the-whale; \
useradd -u ${DOCKER_UID} -m the-whale; \
usermod -G www-data,the-whale,root,adm the-whale
10 changes: 7 additions & 3 deletions inc/SageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ private static function _parse_array(&$variable, SageVariableData $variableData)

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

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

self::_parse_array($alternativesArray, $varData);
if (is_array($alternativesArray)) {
self::_parse_array($alternativesArray, $varData);
} else {
self::_parse_object($alternativesArray, $varData);
}

return $varData->extendedValue;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/SageVariableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function addTabToView($originalVariable, $tabName, $value)
{
if (is_array($value)) {
if (! (reset($value) instanceof self)) {
// concert to SageVariableData[]
// convert to SageVariableData[]
$value = SageParser::alternativesParse($originalVariable, $value);
}
} elseif (is_string($value)) {
Expand Down
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
{
"private": true,
"devDependencies": {
"npm-watch": "^0",
"sass": "^1",
"uglify-js": "^3"
},
"watch": {
"compile-js": "resources/base.js",
"compile-css": "resources/css/*.scss"
},
"scripts": {
"build:js": "uglifyjs resources/base.js -cm --toplevel --mangle-props --warn > resources/compiled/sage.js"
"sass-dev": "sass --watch --update --no-source-map --style=expanded resources/css/themes/:resources/compiled/",
"sass-dev-c": "sass --watch --update --no-source-map --style=compressed resources/css/themes/:resources/compiled/",
"compile-css": "sass --style=compressed --no-source-map resources/css/themes/:resources/compiled/",
"compile-js": "uglifyjs resources/js/base.js -cm --toplevel --mangle-props -o resources/compiled/sage.js",
"watch": "npm-watch",
"build": "npm run compile-js; npm run compile-css"
}
}
25 changes: 14 additions & 11 deletions parsers/SageParsersXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@ class SageParsersXml extends SageParser
{
protected static function parse(&$variable, $varData)
{
try {
if (! SageHelper::isRichMode()) {
return false;
}
if (! SageHelper::isRichMode()) {
return false;
}

if (is_string($variable) && substr($variable, 0, 5) === '<?xml') {
if (is_string($variable) && substr($variable, 0, 5) === '<?xml') {
try {
$e = libxml_use_internal_errors(true);
$xml = simplexml_load_string($variable);
libxml_use_internal_errors($e);
if (empty($xml)) {
return false;
}
} else {
} catch (Exception $e) {
return false;
}
} catch (Exception $e) {

if (empty($xml)) {
return false;
}
} else {
return false;
}

$varData->addTabToView($variable, 'XML', @date('Y-m-d H:i:s', $xml));
// dd($xml);

$varData->addTabToView($variable, 'XML', SageParser::alternativesParse($variable, $xml));
}
}
Loading

0 comments on commit cb97622

Please sign in to comment.