Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $(macro: unsafe) {
- $(lst(chain(
- token('@'),
- chain(
- optional(chain(token("("), token(T_NEW))) as decorator_new,
- ns() as decorator_ns,
- optional(chain(layer(), token(")"))) as decorator_layer
- ) as decorator,
- token('(') as leftParen,
- optional(lst(chain(expression() as param), token(',')) as params),
- token(')') as rightParen),
- token(';')) as decorators)
- $(optional(repeat(either(public, protected, private, static, final, async) as modifier)) as modifiers)
- $(either(ns(), token(T_ARRAY), token(T_CALLABLE), function) as functionType)
- $(ns() as function)
- (
- $(arguments() as args)
- )
- $(optional(chain(token(":"), either(ns(), token(T_ARRAY), token(T_CALLABLE)))) as returnType)
- {
- $(layer() as body)
- }
- } >> {
- $$(trim($(modifiers ...( ) { $(modifier) }))) function $(function)($$(trim($(args ...(, ) { $(arg ... { $(argType) $(argName) $(argAssignment) } )}))))
- {
- $originalFunc = function() use ($$(trim($(args ...(, ) { $(arg ... { $(argName) $(argAssignment) } )})))){
- $(body)
- };
- $decoratedFunc = $$(trim($(decorators ...( ) { $(decorator ... { $(decorator_new) $(decorator_ns) $(decorator_layer) })$(leftParen)$(params ... { $(param), }) }) $originalFunc $(decorators ...( ) { $(rightParen) })));
- return $decoratedFunc();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement