PHP-Parser
PHP-Parser copied to clipboard
Use service container to get instance for new node
For now it's not possible to use you own decorator for node in easy way by Parser component and it's rly hard to redeclare
class MyVariable extends Variable {
}
$serviceContainer = new ServiceContainer();
$serviceContainer->set('Node\Expr\Variable', 'MyVariable')
It's only an idea
You could just use any container and add the nodes you use to it...
Yeap I can use any container, but how are you going to redeclare it in parser?
Redeclare? Could you explain what you are trying to do?
@tleb I guess the idea here is to tell the parser to generate MyVariable
objects instead of normal Variable
objects for $var
nodes (and similarly allow changing the object type for all other nodes as well).
I haven't tried yet, but I suspect that doing this will adversely affect performance. The current alternative is to translate normal nodes to custom ones in a visitor -- is there any problem with doing that?
@nikic https://github.com/ovr/phpsa/blob/master/src/Definition/ClassDefinition.php I would like to write more functions to standart Class_ and use it by default in parser is it clear now? because I am not interested to write decorator or smthg else
I haven't tried yet, but I suspect that doing this will adversely affect performance. The current alternative is to translate normal nodes to custom ones in a visitor -- is there any problem with doing that?
I need to set/get all values from old node to new one :(
Is this issue still valid in php-parser 4.0-alpha?
On second read, you might make use of setAttribute()
method on node to get the extra work.
I do this instead of extending nodes with extra logic in like dozens of cases.
$node->setAttribute('metadata', '...');
What exactly do you need achieve?