/** * Checks if the passed value is valid. * * @param SiteInterface $value The value that should be validated * @param UniqueMainAlias|Constraint $constraint The constraint for the validation * * @api */ public function validate($value, Constraint $constraint) { $result = $this->repository->findOneBySiteId($value->getSiteId()); if (null !== $result && $result->getId() !== $value->getId()) { $this->context->buildViolation($constraint->message)->atPath('siteId')->addViolation(); } }
/** * Checks if the passed value is valid. * * @param SiteInterface $value The value that should be validated * @param UniqueMainAlias|Constraint $constraint The constraint for the validation * * @api */ public function validate($value, Constraint $constraint) { if ($value->getAliases()->filter(function (SiteAliasInterface $alias) { return $alias->isMain(); })->count() > 1) { $this->context->addViolation($constraint->message); } }
/** * Checks if the passed value is valid. * * @param SiteInterface $value The value that should be validated * @param Constraint $constraint The constraint for the validation */ public function validate($value, Constraint $constraint) { try { $value->getMainAlias(); } catch (MainAliasNotExisting $exception) { $this->context->buildViolation($constraint->message)->addViolation(); } }
/** * @param array $sitesNames * @param array $sitesLanguages * @param SiteInterface $site * @param array $prefixes */ protected function addSitesAliases(array $sitesNames, array $sitesLanguages, $site, array $prefixes = array()) { $master = true; foreach ($sitesNames as $siteName) { foreach ($sitesLanguages as $siteLanguage) { $prefix = isset($prefixes[$siteLanguage]) ? $prefixes[$siteLanguage] : null; $site->addAlias($this->generateSiteAlias($siteName, $siteLanguage, $master, $prefix)); $master = false; } } }
/** * @param string $language * * @dataProvider provideAliasIdAndLanguage */ public function testGetAliasIdForLanguage($language) { $alias1 = Phake::mock('OpenOrchestra\\ModelInterface\\Model\\SiteAliasInterface'); Phake::when($alias1)->getLanguage()->thenReturn('fr'); $alias2 = Phake::mock('OpenOrchestra\\ModelInterface\\Model\\SiteAliasInterface'); Phake::when($alias2)->getLanguage()->thenReturn('en'); $this->site->addAlias($alias1); $this->site->addAlias($alias2); $aliases = $this->site->getAliases(); $this->assertTrue($aliases->containsKey($this->site->getAliasIdForLanguage($language))); $this->assertSame($language, $aliases[$this->site->getAliasIdForLanguage($language)]->getLanguage()); }
/** * @param SiteInterface $site * * @return FacadeInterface * * @throws TransformerParameterTypeException */ public function transform($site) { if (!$site instanceof SiteInterface) { throw new TransformerParameterTypeException(); } $facade = $this->newFacade(); $facade->id = $site->getId(); $facade->siteId = $site->getSiteId(); $facade->name = $site->getName(); if ($this->hasGroup(CMSGroupContext::THEME)) { $facade->theme = $this->getTransformer('theme')->transform($site->getTheme()); } if ($this->hasGroup(CMSGroupContext::SITE_MAIN_ALIAS)) { $facade->mainAlias = $this->getTransformer('site_alias')->transform($site->getMainAlias()); } foreach ($site->getLanguages() as $language) { $facade->addLanguage($language); } if ($this->hasGroup(CMSGroupContext::BLOCKS)) { foreach ($site->getBlocks() as $value) { $facade->addBlocks($value); } } $facade->addLink('_self', $this->generateRoute('open_orchestra_api_site_show', array('siteId' => $site->getSiteId()))); if ($this->authorizationChecker->isGranted(AdministrationPanelStrategy::ROLE_ACCESS_DELETE_SITE)) { $facade->addLink('_self_delete', $this->generateRoute('open_orchestra_api_site_delete', array('siteId' => $site->getSiteId()))); } if ($this->authorizationChecker->isGranted(AdministrationPanelStrategy::ROLE_ACCESS_UPDATE_SITE)) { $facade->addLink('_self_form', $this->generateRoute('open_orchestra_backoffice_site_form', array('siteId' => $site->getSiteId()))); } return $facade; }
/** * @param string $message * @param SiteInterface $site */ protected function sendLog($message, SiteInterface $site) { $this->logger->info($message, array('site_id' => $site->getSiteId(), 'site_name' => $site->getName())); }