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

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. /**
  31. * @return array<TwigFunction>
  32. */
  33. public function getFunctions()
  34. {
  35. $result = [];
  36. foreach ($this->extension->getFunctions() as $function) {
  37. /** @var callable $callable */
  38. $callable = $function->getCallable();
  39. $name = $function->getName();
  40. $result[] = new TwigFunction(
  41. $name,
  42. function() use ($callable, $name) {
  43. return $this->memoizeCache->memoizeById($name, \func_get_args(), $callable, $this->lifeTime);
  44. }
  45. );
  46. }
  47. return $result;
  48. }
  49. }