/**
  * 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;
 }
 /**
  * @param MultiTenantTenantInterface $tenant
  * @param string                           $name
  * @param array                            $parameters
  *
  * @return string
  */
 public function generateUrl(MultiTenantTenantInterface $tenant, $parameters = array())
 {
     $url = '';
     $name = $this->redirectRoute;
     if ($this->strategy == TenantResolver::STRATEGY_TENANT_AWARE_SUBDOMAIN) {
         $scheme = $this->requestStack->getCurrentRequest()->getScheme();
         $requestPort = $this->requestStack->getCurrentRequest()->getPort();
         $host = $scheme . '://' . $tenant->getSubdomain() . '.' . $this->domain;
         $port = '';
         if ('http' === $scheme && 80 != $requestPort) {
             $port = ':' . $requestPort;
         } elseif ('https' === $scheme && 443 != $requestPort) {
             $port = ':' . $requestPort;
         }
         $url = $host . $port;
         $url .= $this->router->generate($name, $parameters, self::ABSOLUTE_URL_FALSE);
         return $url;
     } else {
         return $this->router->generate($name, $parameters);
     }
 }
 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()));
 }