Skip to content

Commit

Permalink
Moved environment to Uri object
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Nov 7, 2014
1 parent 699fade commit 78279e4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
19 changes: 6 additions & 13 deletions system/src/Grav/Common/Service/ConfigServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Grav\Common\Config\Config;
use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Filesystem\Folder;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
Expand Down Expand Up @@ -33,7 +34,7 @@ public function register(Container $container)

public function loadMasterConfig(Container $container)
{
$environment = $this->getEnvironment();
$environment = $this->getEnvironment($container);
$file = CACHE_DIR . 'compiled/config/master-'.$environment.'.php';
$data = is_file($file) ? (array) include $file : [];
if ($data) {
Expand All @@ -54,25 +55,17 @@ public function loadMasterConfig(Container $container)

public function loadMasterBlueprints(Container $container)
{
$environment = $this->getEnvironment();
$environment = $this->getEnvironment($container);
$file = CACHE_DIR . 'compiled/blueprints/master-'.$environment.'.php';
$data = is_file($file) ? (array) include $file : [];

return new Blueprints($data, $container);
}

public function getEnvironment()
public function getEnvironment(Container $container)
{
if (!$this->environment) {
$address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '::1';

// check for localhost variations
if ($address == '::1' || $address == '127.0.0.1') {
$hostname = 'localhost';
} else {
$hostname = gethostname();
}
$this->environment = $hostname;
if (!isset($this->environment)) {
$this->environment = $container['uri']->environment();
}

return $this->environment;
Expand Down
35 changes: 30 additions & 5 deletions system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public function __construct()
$root_path = substr($uri, 0, strpos($uri, '/', 1)) . $root_path;
}

// set hostname
$address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '::1';

// check for localhost variations
if ($address == '::1' || $address == '127.0.0.1') {
$this->host = 'localhost';
} else {
$this->host = gethostname();
}

$this->base = $base;
$this->root = $base . $root_path;
$this->url = $base . $uri;
Expand Down Expand Up @@ -213,7 +223,8 @@ public function url($include_host = false)
*
* @return String The path of the URI
*/
public function path() {
public function path()
{
return $this->path;
}

Expand All @@ -222,7 +233,8 @@ public function path() {
*
* @return String The extension of the URI
*/
public function extension($default = null) {
public function extension($default = null)
{
if (!$this->extension) {
$this->extension = $default;
}
Expand All @@ -234,16 +246,28 @@ public function extension($default = null) {
*
* @return String The host of the URI
*/
public function host() {
public function host()
{
return $this->host;
}

/**
* Gets the environment name
*
* @return String
*/
public function environment()
{
return $this->host();
}

/**
* Return the base of the URI
*
* @return String The base of the URI
*/
public function base() {
public function base()
{
return $this->base;
}

Expand Down Expand Up @@ -340,7 +364,8 @@ public function ip()
* @param $parsed_url
* @return string
*/
public static function build_url($parsed_url) {
public static function build_url($parsed_url)
{
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
Expand Down

0 comments on commit 78279e4

Please sign in to comment.