Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple lines in excludeIf expression annotation #314

Open
ixarlie opened this issue Jan 14, 2021 · 0 comments
Open

Allow multiple lines in excludeIf expression annotation #314

ixarlie opened this issue Jan 14, 2021 · 0 comments

Comments

@ixarlie
Copy link
Contributor

ixarlie commented Jan 14, 2021

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

@ixarlie ixarlie changed the title Allow multiple lines in a excludeIf expression annotation Allow multiple lines in excludeIf expression annotation Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants