Skip to content

Commit

Permalink
add config set & get
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanson committed Dec 17, 2018
1 parent a219be6 commit 61d63a8
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/Foundation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ class Foundation extends Container
*/
protected $providers = [];

protected $config;

public function __construct($config)
{
parent::__construct();

$this['config'] = $config;
$this->setConfig($config);

if ($this->config['debug'] ?? false) {
error_reporting(E_ALL);
Expand All @@ -47,8 +49,8 @@ private function registerBase()
return Request::createFromGlobals();
};

if ($cache = $this['config']['cache'] ?? null AND $cache instanceof Cache) {
$this['cache'] = $this['config']['cache'];
if ($cache = $this->getConfig()['cache'] ?? null AND $cache instanceof Cache) {
$this['cache'] = $this->getConfig()['cache'];
} else {
$this['cache'] = function () {
return new FilesystemCache(sys_get_temp_dir());
Expand All @@ -65,18 +67,18 @@ private function initializeLogger()
return;
}

$logger = new Logger($this['config']['log']['name'] ?? 'foundation');
$logger = new Logger($this->getConfig()['log']['name'] ?? 'foundation');

if (!$this['config']['debug'] ?? false || defined('PHPUNIT_RUNNING')) {
if (!$this->getConfig()['debug'] ?? false || defined('PHPUNIT_RUNNING')) {
$logger->pushHandler(new NullHandler());
} elseif (($this['config']['log']['handler'] ?? null) instanceof HandlerInterface) {
$logger->pushHandler($this['config']['log']['handler']);
} elseif ($logFile = $this['config']['log']['file'] ?? null) {
} elseif (($this->getConfig()['log']['handler'] ?? null) instanceof HandlerInterface) {
$logger->pushHandler($this->getConfig()['log']['handler']);
} elseif ($logFile = $this->getConfig()['log']['file'] ?? null) {
$logger->pushHandler(new StreamHandler(
$logFile,
$this['config']['log']['level'] ?? Logger::WARNING,
$this->getConfig()['log']['level'] ?? Logger::WARNING,
true,
$this['config']['log']['permission'] ?? null
$this->getConfig()['log']['permission'] ?? null
));
}

Expand All @@ -93,6 +95,16 @@ protected function registerProviders()
}
}

public function setConfig(array $config)
{
$this->config = $config;
}

public function getConfig($key = null)
{
return $key ? $this->config[$key] : $this->config;
}

/**
* Magic get access.
*
Expand Down

0 comments on commit 61d63a8

Please sign in to comment.