/**
  * Enables tenantable filter on kernel.request.
  */
 public function onKernelRequest()
 {
     $tenant = $this->tenantContext->getTenant();
     if ($tenant && $tenant->getId()) {
         $this->entityManager->getFilters()->enable('tenantable')->setParameter('tenantCode', $tenant->getCode());
     }
 }
 public function it_should_return_global_variables(TenantInterface $tenant, TenantContextInterface $tenantContext)
 {
     $tenant->getSubdomain()->willReturn('example');
     $tenant->getName()->willReturn('example tenant');
     $tenantContext->getTenant()->shouldBeCalled()->willReturn($tenant);
     $globals = ['tenant' => $tenant];
     $this->getGlobals()->shouldReturn($globals);
 }
 public function let(TenantContextInterface $tenantContext)
 {
     $currentTenant = new Tenant();
     $currentTenant->setName('Default');
     $currentTenant->setSubdomain('default');
     $tenantContext->getTenant()->willReturn($currentTenant);
     $this->beConstructedWith($tenantContext, '/swp');
 }
 public function it_throws_no_theme_exception_if_tenant_has_no_theme(TenantContextInterface $tenantContext, ThemeAwareTenantInterface $tenant, $themeRepository)
 {
     $tenant->getSubdomain()->willReturn('subdomain');
     $tenant->getCode()->willReturn('code');
     $tenant->getThemeName()->willReturn(null);
     $tenantContext->getTenant()->willReturn($tenant);
     $themeRepository->findOneByName(null)->shouldBeCalled()->willReturn(null);
     $this->shouldThrow('SWP\\Bundle\\CoreBundle\\Exception\\NoThemeException')->during('getTheme');
 }
示例#5
0
 private function filterThemesByTenantCode(array $themes)
 {
     $currentTenantCode = $this->tenantContext->getTenant()->getCode();
     foreach ($themes as $key => $theme) {
         if (strpos($key, ThemeHelper::SUFFIX_SEPARATOR . $currentTenantCode) !== false) {
             $theme->setName(strstr($theme->getName(), ThemeHelper::SUFFIX_SEPARATOR, true));
             (yield $theme);
         }
     }
 }
 public function checkCredentials($credentials, UserInterface $user)
 {
     if ($user instanceof User) {
         $currentTenantOrganization = $this->tenantContext->getTenant()->getOrganization();
         $userTenantOrganization = $this->tenantRepository->findOneByCode($user->getTenantCode());
         if ($currentTenantOrganization->getId() === $userTenantOrganization->getId()) {
             return true;
         }
     }
     return false;
 }
 public function let(TenantContextInterface $tenantContext)
 {
     $currentTenant = new Tenant();
     $currentTenant->setName('Default');
     $currentTenant->setSubdomain('default');
     $currentTenant->setCode(654321);
     $organization = new Organization();
     $organization->setCode(123456);
     $currentTenant->setOrganization($organization);
     $tenantContext->getTenant()->willReturn($currentTenant);
     $this->beConstructedWith($tenantContext, '/swp');
 }
 public function it_sets_the_tenant_code_on_pre_persist_doctrine_event(TenantContextInterface $tenantContext, LifecycleEventArgs $event, TenantAwareInterface $tenantAware, ContainerInterface $container)
 {
     $tenant = new Tenant();
     $tenant->setSubdomain('example.com');
     $tenant->setName('Example');
     $tenant->setCode('123456');
     $tenantAware->getTenantCode()->shouldBeCalled()->willReturn(null);
     $event->getEntity()->willReturn($tenantAware);
     $tenantContext->getTenant()->shouldBeCalled()->willReturn($tenant);
     $tenantAware->setTenantCode('123456')->shouldBeCalled();
     $container->get('swp_multi_tenancy.tenant_context')->willReturn($tenantContext);
     $this->prePersist($event)->shouldBeNull();
 }
 /**
  * Makes PHPCR tree root path to be tenant aware.
  *
  * When tenant is not available in tenant context it will resolve
  * the tenant from current request.
  */
 protected function makePathTenantAware()
 {
     if ($this->latestRootPath === $this->rootPath) {
         return;
     }
     $tenant = $this->tenantContext->getTenant();
     $this->rootPath = $this->absolutizePath($tenant->getSubdomain());
     $this->latestRootPath = $this->rootPath;
 }
 /**
  * {@inheritdoc}
  */
 public function getTheme()
 {
     /* @var ThemeAwareTenantInterface $tenant */
     $tenant = $this->tenantContext->getTenant();
     $key = md5($tenant->getCode());
     if (array_key_exists($key, $this->themes)) {
         return $this->themes[$key];
     }
     if ($this->cacheService->contains('theme_' . $key)) {
         return $this->themes[$key] = $this->cacheService->fetch('theme_' . $key);
     }
     $theme = $this->themeRepository->findOneByName($this->resolveThemeName($tenant));
     unset($tenant);
     if (null === $theme) {
         throw new NoThemeException();
     }
     $this->themes[$key] = $theme;
     $this->cacheService->save('theme_' . $key, $theme, 600);
     return $theme;
 }
 /**
  * Makes PHPCR tree root path to be tenant aware.
  *
  * When tenant is not available in tenant context it will resolve
  * the tenant from current request.
  */
 protected function makePathTenantAware()
 {
     if ($this->latestRootPath === $this->rootPath) {
         return;
     }
     $tenant = $this->tenantContext->getTenant();
     $path = $tenant->getCode();
     if (null !== $tenant->getOrganization()) {
         $path = $tenant->getOrganization()->getCode() . '/' . $path;
     }
     $this->rootPath = $this->absolutizePath($path);
     $this->latestRootPath = $this->rootPath;
 }
 /**
  * {@inheritdoc}
  */
 public function getGlobals()
 {
     return ['tenant' => $this->tenantContext->getTenant()];
 }
示例#13
0
 protected function getMediaBasePath() : string
 {
     $tenant = $this->tenantContext->getTenant();
     $pathElements = ['swp', $tenant->getOrganization()->getCode(), $tenant->getCode(), 'media'];
     return implode('/', $pathElements);
 }