/**
  * Returns an tenant id based on current url
  *
  * @return int
  * @throws \Exception
  */
 public function getTenantId()
 {
     if ($this->tenant === null) {
         $this->tenant = $this->resolveTenant();
     }
     return $this->tenant ? $this->tenant->getId() : null;
 }
 public function removeRoleFromUserInTenant($role, MultiTenantUserInterface $user, MultiTenantTenantInterface $tenant)
 {
     $tenantUser = $this->tenantUserRepository->findOneBy(array('tenant' => $tenant, 'user' => $user));
     if ($tenantUser) {
         if ($tenantUser->hasRole($role)) {
             $tenantUser->removeRole($role);
         }
         $this->entityManager->persist($tenantUser);
         $this->entityManager->flush();
         return true;
     }
     throw new \Exception(sprintf('User with id %d is not a member of tenant with id %d', $user->getId(), $tenant->getId()));
 }