Erster Stand des mvc-Frameworks
This commit is contained in:
77
rendering/Helper/Environment.php
Normal file
77
rendering/Helper/Environment.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Hilfsklasse zum Auslesen der Umgebungsvariablen, die in einer .htaccess gesetzt sind
|
||||
*
|
||||
* @author Christian Steinle
|
||||
* @date 02.08.2016
|
||||
*
|
||||
* @copyright CS medien- & kommunikationssysteme (http://www.steinle-computer.de)
|
||||
*/
|
||||
|
||||
namespace Helper;
|
||||
use Singleton\SingletonAbstract;
|
||||
|
||||
|
||||
class Environment extends SingletonAbstract
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected static $_environment = '';
|
||||
|
||||
|
||||
/**
|
||||
* @return Environment|null
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (null === self::$_instance)
|
||||
{
|
||||
self::$_instance = new self;
|
||||
self::setEnvironment();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Falls ein Skript via Apache gestartet wird, zieht getenv.
|
||||
* Andernfalls werden die Informationen aus einer .htaccess im FileSystem ausgelesen.
|
||||
*/
|
||||
protected static function setEnvironment()
|
||||
{
|
||||
$environment = getenv('ENVIRONMENT');
|
||||
if ($environment === false)
|
||||
{
|
||||
$tmpPath = __DIR__;
|
||||
while ($tmpPath != '/')
|
||||
{
|
||||
$htFile = $tmpPath . '/.htaccess';
|
||||
if (is_file($htFile) && is_readable($htFile))
|
||||
{
|
||||
$htContent = file($htFile);
|
||||
foreach ($htContent as $line => $text)
|
||||
{
|
||||
if (strpos($text, 'SetEnv') !== false && strpos($text, 'ENVIRONMENT') !== false)
|
||||
{
|
||||
self::$_environment = trim(str_replace(array('SetEnv', 'ENVIRONMENT'), '', $text));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
$tmpPath = dirname($tmpPath);
|
||||
}
|
||||
$environment = '';
|
||||
}
|
||||
self::$_environment = $environment;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function getEnvironment()
|
||||
{
|
||||
return self::$_environment;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user