IsGrantedPreviousAdminExtension.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Base\OAuthClientBundle\Twig;
  3. use WebserviceBundle\Services\Webservice;
  4. class IsGrantedPreviousAdminExtension extends \Twig_Extension
  5. {
  6. /**
  7. * @var Webservice
  8. */
  9. protected $webservice;
  10. /**
  11. * @var string
  12. */
  13. protected $urlBase;
  14. /**
  15. * @param Webservice $webservice
  16. * @param string $urlBase
  17. */
  18. public function __construct(Webservice $webservice, $urlBase)
  19. {
  20. $this->webservice = $webservice;
  21. $this->urlBase = $urlBase;
  22. }
  23. /**
  24. * @return array
  25. */
  26. public function getFunctions()
  27. {
  28. return array(
  29. new \Twig_SimpleFunction('is_granted_previous_admin', array($this, 'isGrantedPreviousAdmin')),
  30. new \Twig_SimpleFunction('switch_user_exit', array($this, 'switchUserExit')),
  31. );
  32. }
  33. /**
  34. * @return boolean
  35. */
  36. public function isGrantedPreviousAdmin()
  37. {
  38. return $this->webservice->makeGetRequest($this->urlBase . '/admin/user/is_granted');
  39. }
  40. /**
  41. * @return boolean
  42. */
  43. public function switchUserExit()
  44. {
  45. return 'https://' . $this->urlBase . '/?_switch_user=_exit';
  46. }
  47. /**
  48. * @return string
  49. */
  50. public function getName()
  51. {
  52. return 'is_granted_previous_admin_extension';
  53. }
  54. }