Source of file ReleaseStage.php
Size: 3,351 Bytes - Last Modified: 2021-12-24T06:47:01+00:00
/var/www/docs.ssmods.com/process/src/code/ReleaseStage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 | <?php /* * This file is part of the Silverstripe Bugsnag Logger. * * (c) Evolution 7 <http://www.evolution7.com.au> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * The evReleaseStage class is responsible for determining the environment/stage * of the current release. * * There are currently four valid release stages: * - development * - testing * - staging * - production */ class ReleaseStage implements ReleaseStageInterface { const DEVELOPMENT = 'development'; const TESTING = 'testing'; const STAGING = 'staging'; const PRODUCTION = 'production'; protected static $current; /** * Get release stage * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.NPathComplexity) * * @return string $releaseStage */ public function get() { // Check if current set if (is_null(self::$current)) { // Get environment variable (if set and valid) $releaseStage = trim(getenv('RELEASE_STAGE')); $releaseStage = (in_array($releaseStage, $this->getAll())) ? $releaseStage : null; // If environment variable not set/valid, try to detect staging environment by url or path if (is_null($releaseStage)) { // Create paths variable with host name, document root and file path $paths = __FILE__ . (array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : '') . (array_key_exists('DOCUMENT_ROOT', $_SERVER) ? $_SERVER['DOCUMENT_ROOT'] : ''); // Now check if paths variable contains "stage" or "staging" keywords if (strpos($paths, 'stage') !== false || strpos($paths, 'staging') !== false) { // Set release stage to staging $releaseStage = self::STAGING; } elseif((strpos(__FILE__, '/home') !== false && strpos(__FILE__, 'vhosts') !== false) || file_exists('/home/vagrant')) { //Check for dev environment that works with cli scripts $releaseStage = self::DEVELOPMENT; } } // If environment variable still not set, assume we are in production! $releaseStage = is_null($releaseStage) ? self::PRODUCTION : $releaseStage; self::$current = $releaseStage; } return self::$current; } /** * Get all release stages * * @return array $releaseStages */ public function getAll() { return array( self::DEVELOPMENT => self::DEVELOPMENT, self::TESTING => self::TESTING, self::STAGING => self::STAGING, self::PRODUCTION => self::PRODUCTION, ); } /** * Check if release stage is development * * @return boolean $is_development */ public function isDevelopment() { return $this->get() === self::DEVELOPMENT; } /** * Check if release stage is testing * * @return boolean $is_testing */ public function isTesting() { return $this->get() === self::TESTING; } /** * Check if release stage is staging * * @return boolean $is_staging */ public function isStaging() { return $this->get() === self::STAGING; } /** * Check if release stage is production * * @return boolean $is_production */ public function isProduction() { return $this->get() === self::PRODUCTION; } } |