Hateoas
Hateoas copied to clipboard
Allow multiple lines in excludeIf expression annotation
I have some issues when I use the excludeIf
option with a large expression in the annotation.
I want to split it to see the entire expression without scrolling horizontally.
Example
/**
* @Hateoas\Relation(
* name="foo"
* embedded=@Hateoas\Embedded(
* "expr(object.getA().getB().getC().getD()",
* exclusion=@Hateoas\Exclusion(
* groups={"public"},
* excludeIf="expr(not object.getA()
or not object.getA().getB()
or not object.getA().getB().getC())"
* )
* )
* )
*/
class Group
The CheckExpressionTrait::checkExpression
method gets the expression like this expr(not object.getA()\n or not object.getA().getB()\n or not object.getA().getB().getC())
.
The Symfony Expression Language component will replace all the \n
with whitespaces, but the regular expression is not taking the entire expression.
https://github.com/willdurand/Hateoas/blob/master/src/Configuration/Metadata/Driver/CheckExpressionTrait.php#L25
if (is_string($exp) && preg_match('/expr\((?P<expression>.+)\)/', $exp, $matches)) {
So the matching in the expression group is not object.getA(
I am not sure if the regular expression can be updated to use "single line" flag, /expr\((?P<expression>.+)\)/s
, so dots matches newline.
Thanks