1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace Base\OAuthClientBundle\Twig;
- use WebserviceBundle\Services\Webservice;
- class IsGrantedPreviousAdminExtension extends \Twig_Extension
- {
- /**
- * @var Webservice
- */
- protected $webservice;
- /**
- * @var string
- */
- protected $urlBase;
- /**
- * @param Webservice $webservice
- * @param string $urlBase
- */
- public function __construct(Webservice $webservice, $urlBase)
- {
- $this->webservice = $webservice;
- $this->urlBase = $urlBase;
- }
- /**
- * @return array
- */
- public function getFunctions()
- {
- return array(
- new \Twig_SimpleFunction('is_granted_previous_admin', array($this, 'isGrantedPreviousAdmin')),
- new \Twig_SimpleFunction('switch_user_exit', array($this, 'switchUserExit')),
- );
- }
- /**
- * @return boolean
- */
- public function isGrantedPreviousAdmin()
- {
- return false;
- try {
- return $this->webservice->makeGetRequest($this->urlBase . '/admin/user/is_granted');
- } catch (\Exception $e) {
- return false;
- }
- }
- /**
- * @return boolean
- */
- public function switchUserExit()
- {
- return 'https://' . $this->urlBase . '/?_switch_user=_exit';
- }
- /**
- * @return string
- */
- public function getName()
- {
- return 'is_granted_previous_admin_extension';
- }
- }
|