OpenConext / OpenConext-manage

Stores and publishes metadata of all entities known to OpenConext
Apache License 2.0
7 stars 10 forks source link

Attribute manipulation should be syntax-checked #136

Open baszoetekouw opened 3 weeks ago

baszoetekouw commented 3 weeks ago

To catch obvious mistakes, it would be nice if we could syntax-check the AM PHP code before it can be submitted. Also adding syntax-coloring would help to catch problems.

thijskh commented 1 day ago

This is a bit of a challenge since Manage is obviously not PHP.

One, slightly crude approach could be that EB syntax checks any incoming manipulation on PUSH, and refuses to update when this has a syntax error

pmeulen commented 1 day ago

There is no native PHP way to syntax check an AM AFIK. You either eval / include the php code or you invoke the php binary with the -l option. A client side syntax hi-lighting exists (e.g. highlight.js). I think a syntax hi-light might already help a lot with catching syntax errors. In the end the idea is minimalise th use attribute manipulations.

tvdijen commented 1 day ago

There are ways to do something with the result of highlight.js: https://highlightjs.readthedocs.io/en/latest/plugin-recipes.html

Could make the save-button greyed-out if the result indicates a syntax error?

thijskh commented 1 day ago

I've tested it and this works to test any AM code for parse errors:

try {
    @eval($am);
} catch (ParseError $e) {
    echo "Dat ging dus mis. Want: " . $e->getMessage();
    exit(1);
}

The monkey tail is there to avoid notices and warnings because the needed variables for an AM to function are not set.