Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. <?php
  2.  
  3. $(macro: unsafe) {
  4. $(lst(chain(
  5. token('@'),
  6. chain(
  7. optional(chain(token("("), token(T_NEW))) as decorator_new,
  8. ns() as decorator_ns,
  9. optional(chain(layer(), token(")"))) as decorator_layer
  10. ) as decorator,
  11. token('(') as leftParen,
  12. optional(lst(chain(expression() as param), token(',')) as params),
  13. token(')') as rightParen),
  14. token(';')) as decorators)
  15. $(optional(repeat(either(public, protected, private, static, final, async) as modifier)) as modifiers)
  16. $(either(ns(), token(T_ARRAY), token(T_CALLABLE), function) as functionType)
  17. $(ns() as function)
  18. (
  19. $(arguments() as args)
  20. )
  21. $(optional(chain(token(":"), either(ns(), token(T_ARRAY), token(T_CALLABLE)))) as returnType)
  22. {
  23. $(layer() as body)
  24. }
  25. } >> {
  26. $$(trim($(modifiers ...( ) { $(modifier) }))) function $(function)($$(trim($(args ...(, ) { $(arg ... { $(argType) $(argName) $(argAssignment) } )}))))
  27. {
  28. $originalFunc = function() use ($$(trim($(args ...(, ) { $(arg ... { $(argName) $(argAssignment) } )})))){
  29. $(body)
  30. };
  31. $decoratedFunc = $$(trim($(decorators ...( ) { $(decorator ... { $(decorator_new) $(decorator_ns) $(decorator_layer) })$(leftParen)$(params ... { $(param), }) }) $originalFunc $(decorators ...( ) { $(rightParen) })));
  32. return $decoratedFunc();
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement