bundle/w3des/AdminBundle/src/Twig/Runtime/NodeRuntime.php line 22

Open in your IDE?
  1. <?php
  2. namespace w3des\AdminBundle\Twig\Runtime;
  3. use Twig\Extension\RuntimeExtensionInterface;
  4. use w3des\AdminBundle\Service\Nodes;
  5. class NodeRuntime implements RuntimeExtensionInterface
  6. {
  7. private Nodes $nodes;
  8. public function __construct(Nodes $nodes)
  9. {
  10. $this->nodes = $nodes;
  11. }
  12. public function getNodes($type, $cfg = [])
  13. {
  14. return $this->nodes->getNodes($type, $cfg);
  15. }
  16. public function getNodeTTL($type, $cfg = [], $field)
  17. {
  18. $nodes = $this->nodes->getNodes($type, $cfg);
  19. if (count($nodes['list']) == 0) {
  20. return null;
  21. }
  22. $f = $nodes['list'][0]->vars->get($field);
  23. return $f->getTimestamp() - time() + 1;
  24. }
  25. public function getNode($type, $cfg = [])
  26. {
  27. $cfg['max'] = 1;
  28. $res = $this->nodes->getNodes($type, $cfg);
  29. if (count($res['list'])) {
  30. return \array_shift($res['list']);
  31. }
  32. return null;
  33. }
  34. }