From 1d9763eae5a889409ca8e091de4c74c2e7e44ab9 Mon Sep 17 00:00:00 2001 From: Matthias Van Woensel <3532563+matthiaz@users.noreply.github.com> Date: Wed, 12 Jul 2023 12:37:58 +0200 Subject: [PATCH] adding isDomainAdded function This allows users to detect if they are on a production site that actually has a domain added. Can also be used to detect if a dev environment has a domain. --- src/Config.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Config.php b/src/Config.php index 8fa32ea..0eaf16d 100644 --- a/src/Config.php +++ b/src/Config.php @@ -442,6 +442,27 @@ public function onProduction() : bool return $this->getValue('BRANCH') == $prodBranch; } + /** + * Determines if the current environment has a live domain added to it + * + * @return bool + * True if the environment has at least one domain that is not ending in platformsh.site, false otherwise. + * It will also return false if not running on Platform.sh or in the build phase. + */ + public function isDomainAdded(): bool + { + if (!$this->inRuntime()) { + return false; + } + + foreach ($this->routes() as $route) { + if (mb_strpos($route['url'], 'platformsh.site') === false) { + return true; + } + } + + return false; + } /** * Adds a credential formatter to the configuration. *