RemoteClientExtension.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace WebserviceBundle\Twig;
  3. use WebserviceBundle\Services\Webservice;
  4. class RemoteClientExtension extends \Twig_Extension
  5. {
  6. /**
  7. * @var Webservice
  8. */
  9. protected $webservice;
  10. /**
  11. * @param Webservice $webservice
  12. */
  13. public function __construct(Webservice $webservice)
  14. {
  15. $this->webservice = $webservice;
  16. }
  17. /**
  18. * @return array
  19. */
  20. public function getFunctions()
  21. {
  22. return array(
  23. new \Twig_SimpleFunction('remote_client', array($this, 'getClient')),
  24. );
  25. }
  26. /**
  27. * @param int $clientId
  28. * @return string
  29. */
  30. public function getClient($clientId)
  31. {
  32. $client = $this->webservice->getArray('client', array(
  33. 'id' => $clientId
  34. ));
  35. return isset($client[0]) ? "{$client[0]['id']} - {$client[0]['name']}" : $clientId;
  36. }
  37. /**
  38. * @return string
  39. */
  40. public function getName()
  41. {
  42. return 'remote_client_extension';
  43. }
  44. }