From b35163e619b53777a7466e64ff7ad8b5eaf9fdcd Mon Sep 17 00:00:00 2001 From: Wolfgang Ziegler // fago Date: Mon, 8 Jul 2019 17:54:44 +0200 Subject: [PATCH] Bugfix: Dashes in environment variable names are not allowed, replace dashes in site names with underscores. --- README.md | 2 +- src/RequestMatcher.php | 2 +- tests/src/RequestMatcherTest.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f0f8167..c88f516 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ The following environment variables may be set to configure the request matcher: | APP_SITE_VARIANT_SEPARATOR | No | -- | The separator between the variant name and the host, defaults to "--". | | APP_MULTISITE_DOMAIN | ~ | stage.codebase.dev | A common base domain for all sites. Required when multisite base domains should be used. | | APP_MULTISITE_DOMAIN_PREFIX_SEPARATOR | No | _ | The separator between the site name and the common multisite base domain. Defaults to '_'. | -| APP_SITE_DOMAIN__{{ SITE }} | ~ | site-a.com | The per-site domain - required when per-site domains should be used. One variable per site must be provided, e.g. for site-a the variable name would be `APP_SITE_DOMAIN__site-a` | +| APP_SITE_DOMAIN__{{ SITE }} | ~ | site-a.com | The per-site domain - required when per-site domains should be used. One variable per site must be provided with dashes replaced to underscores, e.g. for site-a the variable name would be `APP_SITE_DOMAIN__site_a` | ## Results diff --git a/src/RequestMatcher.php b/src/RequestMatcher.php index eee8cde..0bfa432 100644 --- a/src/RequestMatcher.php +++ b/src/RequestMatcher.php @@ -280,7 +280,7 @@ public function match(Request $request = NULL) { $matches = []; $variants = implode('|', $this->variants); foreach ($this->sites as $current_site) { - $site_domain = getenv('APP_SITE_DOMAIN__' . $current_site); + $site_domain = getenv('APP_SITE_DOMAIN__' . str_replace('-', '_', $current_site)); if (empty($site_domain)) { throw new RequestMatchException("Missing API_SITE_DOMAIN environment variable for site " . strip_tags($current_site) . "."); } diff --git a/tests/src/RequestMatcherTest.php b/tests/src/RequestMatcherTest.php index 741c4b1..6416f0d 100644 --- a/tests/src/RequestMatcherTest.php +++ b/tests/src/RequestMatcherTest.php @@ -54,8 +54,8 @@ public function testMatch() { putenv("APP_SITE_VARIANTS=api admin"); putenv("APP_DEFAULT_SITE=site-a"); putenv("APP_SITES=site-a site-b"); - putenv("APP_SITE_DOMAIN__site-a=site-a.com"); - putenv("APP_SITE_DOMAIN__site-b=site-b.com"); + putenv("APP_SITE_DOMAIN__site_a=site-a.com"); + putenv("APP_SITE_DOMAIN__site_b=site-b.com"); $this->assertHostMatches('site-a.com', 'site-a', ''); $this->assertHostMatches('api.site-a.com', 'site-a', 'api'); $this->assertHostMatches('admin.site-a.com', 'site-a', 'admin'); @@ -71,8 +71,8 @@ public function testMatch() { putenv("APP_SITE_VARIANT_SEPARATOR=."); putenv("APP_DEFAULT_SITE=site-a"); putenv("APP_SITES=site-a site-b"); - putenv("APP_SITE_DOMAIN__site-a=site-a.com"); - putenv("APP_SITE_DOMAIN__site-b=site-b.com"); + putenv("APP_SITE_DOMAIN__site_a=site-a.com"); + putenv("APP_SITE_DOMAIN__site_b=site-b.com"); $this->assertHostMatches('site-a.com', 'site-a', ''); $this->assertHostMatches('site-b.com', 'site-b', ''); $this->assertHostDoesNotMatch('com');