BreakpointExtension.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * AJGL Breakpoint Twig Extension Component
  4. *
  5. * Copyright (C) Antonio J. García Lagar <aj@garcialagar.es>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Ajgl\Twig\Extension;
  11. use Twig\Environment;
  12. use Twig\Extension\AbstractExtension;
  13. use Twig\TwigFunction;
  14. /**
  15. * @author Antonio J. García Lagar <aj@garcialagar.es>
  16. */
  17. class BreakpointExtension extends AbstractExtension
  18. {
  19. public function getName()
  20. {
  21. return 'breakpoint';
  22. }
  23. public function getFunctions()
  24. {
  25. return [
  26. new TwigFunction('breakpoint', [$this, 'setBreakpoint'], ['needs_environment' => true, 'needs_context' => true]),
  27. ];
  28. }
  29. /**
  30. * If Xdebug is detected, makes the debugger break.
  31. *
  32. * @param Environment $environment the environment instance
  33. * @param mixed $context variables from the Twig template
  34. */
  35. public function setBreakpoint(Environment $environment, $context)
  36. {
  37. if (function_exists('xdebug_break')) {
  38. $arguments = func_get_args();
  39. $arguments = array_slice($arguments, 2);
  40. xdebug_break();
  41. }
  42. }
  43. }