vendor/sulu/sulu/src/Sulu/Component/Cache/MemoizeTwigExtensionTrait.php line 48

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Sulu.
  4. *
  5. * (c) Sulu GmbH
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Sulu\Component\Cache;
  11. use Twig\Extension\ExtensionInterface;
  12. use Twig\TwigFunction;
  13. /**
  14. * Provides functionality to convert twig functions.
  15. */
  16. trait MemoizeTwigExtensionTrait
  17. {
  18. /**
  19. * @var ExtensionInterface
  20. */
  21. protected $extension;
  22. /**
  23. * @var MemoizeInterface
  24. */
  25. protected $memoizeCache;
  26. /**
  27. * @var int
  28. */
  29. protected $lifeTime;
  30. public function getFunctions()
  31. {
  32. $result = [];
  33. foreach ($this->extension->getFunctions() as $function) {
  34. /** @var callable $callable */
  35. $callable = $function->getCallable();
  36. $name = $function->getName();
  37. $result[] = new TwigFunction(
  38. $name,
  39. function() use ($callable, $name) {
  40. return $this->memoizeCache->memoizeById($name, \func_get_args(), $callable, $this->lifeTime);
  41. }
  42. );
  43. }
  44. return $result;
  45. }
  46. }