IsGrantedPreviousAdminExtension.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 false;
  39. try {
  40. return $this->webservice->makeGetRequest($this->urlBase . '/admin/user/is_granted');
  41. } catch (\Exception $e) {
  42. return false;
  43. }
  44. }
  45. /**
  46. * @return boolean
  47. */
  48. public function switchUserExit()
  49. {
  50. return 'https://' . $this->urlBase . '/?_switch_user=_exit';
  51. }
  52. /**
  53. * @return string
  54. */
  55. public function getName()
  56. {
  57. return 'is_granted_previous_admin_extension';
  58. }
  59. }