public function testHostCulture() { $routing = $this->loadRoutingService(); try { $routing->getHostForCulture('fr'); $this->fail('Should throw [Nucleus\\IService\\Routing\\NoHostFoundForCultureException]'); } catch (NoHostFoundForCultureException $exception) { $this->assertEquals(NoHostFoundForCultureException::formatMessage('fr'), $exception->getMessage()); } $routing->setHostForCulture('fr.test.com', 'fr'); $this->assertEquals('fr.test.com', $routing->getHostForCulture('fr_FR')); $routing->setHostForCulture('fr-fr.test.com', 'fr_FR'); $this->assertEquals('fr-fr.test.com', $routing->getHostForCulture('fr_FR')); $routing->setHostForCulture('www.test.com'); $this->assertEquals('www.test.com', $routing->getHostForCulture('en_US')); }
/** * @param string $culture * @return string * @throws NoHostFoundForCultureException * @throws \InvalidArgumentException */ public function getHostForCulture($culture = 'default') { $culture = $this->normalizeCulture($culture); if (array_key_exists($culture, $this->cultureHosts)) { return $this->cultureHosts[$culture]; } if ($culture == 'default') { throw new NoHostFoundForCultureException(NoHostFoundForCultureException::formatMessage($culture)); } try { return $this->getHostForCulture(get_parent_culture($culture)); } catch (NoHostFoundForCultureException $e) { throw new NoHostFoundForCultureException(NoHostFoundForCultureException::formatMessage($culture)); } }