You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.
These expressions are getting really complex. I could just use parseExpression and feed it raw PHP, of course, but that's not ideal, especially considering that the chaining stuff we added to CallNode is so elegant and works so well.
What would be amazing -- and I can't honestly call this high priority, but it'd be extremely nice to have -- is the ability to chain different kinds of expressions beyond just CallNodes. Obviously not every type of expression can be chained, so I'm thinking we could devise a ChainableExpression interface (extending Expression), which exposes an appendExpression() method. This method accepts an Expression, and then returns $existingChain->$appendedExpr. And if the resulting chain is itself a chainable expression, it can be chained again.
So I envision something like the following:
// VariableNode will implement ChainableExpression$var = Token::variable('$node')
// $body is an ArrayLookupNode: body[0]
$var = $var->appendExpression($body)
// $var is now $node->body[0]
$value = Token::string('value')
$var = $var->appendExpression($value)
// $var is now $node->body[0]->value
$get = FunctionCallNode::create('get')
$var = $var->appendExpression($get)
// $var is now $node->body[0]->value->get()
The text was updated successfully, but these errors were encountered:
I still think these should be defined on an interface, if for no other reason than it keeps it clear as to what types of nodes support chaining (if I'm not forgetting any, that'll be CallNode, VariableNode, ObjectPropertyNode, and ArrayLookupNode).
Yes could be interface if there a need to identify which nodes support it. Note that a lot of the traits don't have an associated interface though to identify which nodes support those operations. Whether they should or not... not sure. Just making observation there.
And probably have a Trait for implementation here since I believe the same implementation should be the same across the board.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In DMU, I'm starting to need to build constructs like this:
$node->field_foo[0]->value
$node->getTranslation('fr')->field_foo[0]->value
These expressions are getting really complex. I could just use parseExpression and feed it raw PHP, of course, but that's not ideal, especially considering that the chaining stuff we added to CallNode is so elegant and works so well.
What would be amazing -- and I can't honestly call this high priority, but it'd be extremely nice to have -- is the ability to chain different kinds of expressions beyond just CallNodes. Obviously not every type of expression can be chained, so I'm thinking we could devise a ChainableExpression interface (extending Expression), which exposes an appendExpression() method. This method accepts an Expression, and then returns $existingChain->$appendedExpr. And if the resulting chain is itself a chainable expression, it can be chained again.
So I envision something like the following:
The text was updated successfully, but these errors were encountered: