2015-02-16 15:31 GMT+03:00 Benjamin Eberlei <[email protected]>: > > My question is how do i evaluate this at runtime? I suppose a function is > necessary like evaluate_ast(...), but that requires passing the context. > many many open questions and as nikic points out this should probably be > delayed to 7.1 because it all should be discussed and specified. >
This will be like pretty simple to parse: // For scalars: $attributes = (new ReflectionMethod(some::class, 'method))->getAttributes(); $cacheableNode = $attributes[Cacheable::class] ?? new Php\Parser\Node(AST_TYPE_VALUE, 50); $cacheTime = $cacheableNode->value; // For more complex things, like expressions or constant, runtime evaluation can be performed. $codeNode = $attributes[Php\Contract\Requires::class] ?? new Php\Parser\Node(AST_TYPE_STATEMENT, '$this->value >=0'); $code = (string) $codeNode; $result = eval($code);
