RemoteClientExtension.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * @var string
  12. */
  13. protected $remoteClientCreateUrl;
  14. /**
  15. * @param Webservice $webservice
  16. * @param string $remoteClientCreateUrl
  17. */
  18. public function __construct(Webservice $webservice, $remoteClientCreateUrl)
  19. {
  20. $this->webservice = $webservice;
  21. $this->remoteClientCreateUrl = $remoteClientCreateUrl;
  22. }
  23. /**
  24. * @return array
  25. */
  26. public function getFunctions()
  27. {
  28. return array(
  29. new \Twig_SimpleFunction('remote_client', array($this, 'getClient')),
  30. new \Twig_SimpleFunction('remote_client_url', array($this, 'getClientCreateUrl')),
  31. );
  32. }
  33. /**
  34. * @param int $clientId
  35. *
  36. * @return string
  37. */
  38. public function getClient($clientId)
  39. {
  40. return $this->webservice->getById('client', $clientId);
  41. }
  42. /**
  43. * @return string
  44. */
  45. public function getClientCreateUrl()
  46. {
  47. return $this->remoteClientCreateUrl;
  48. }
  49. /**
  50. * @return string
  51. */
  52. public function getName()
  53. {
  54. return 'remote_client_extension';
  55. }
  56. }