Skip to content

Commit

Permalink
Some strict methods. use DI Container from utils part.
Browse files Browse the repository at this point in the history
  • Loading branch information
vasiliishvakin committed Apr 12, 2017
1 parent e2097df commit 24da12b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 56 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

"require": {
"php": "^5.6 || ^7.0",
"akademiano/utils": "^1.0.0-beta.1",
"pimple/pimple": "^3.0"
"akademiano/utils": "^1.0.0-beta.2"
},
"require-dev": {
"codeception/codeception": "^2.2.10",
Expand Down
25 changes: 5 additions & 20 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
namespace Akademiano\Config;

use Akademiano\Utils\ArrayTools;
use Akademiano\Utils\DIContainerIncludeInterface;
use Akademiano\Utils\Object\Collection;
use Akademiano\Utils\Parts\DIContainerTrait;
use Pimple\Container;

class Config implements \ArrayAccess, \IteratorAggregate
class Config implements \ArrayAccess, \IteratorAggregate, DIContainerIncludeInterface
{
use DIContainerTrait;

const DYN_CONF = "__dynamic__";

protected $configRaw;
Expand All @@ -16,9 +20,6 @@ class Config implements \ArrayAccess, \IteratorAggregate

protected $environment;

/** @var Container */
protected $diContainer;

public function __construct(array $config, Container $diContainer = null)
{
$this->set($config);
Expand All @@ -35,22 +36,6 @@ public function getEnvironment()
return $this->getDiContainer()["environment"];
}

/**
* @return DI
*/
public function getDiContainer()
{
return $this->diContainer;
}

/**
* @param Container $diContainer
*/
public function setDiContainer(Container $diContainer)
{
$this->diContainer = $diContainer;
}

public function set($data, array $path = null)
{
$this->childConfig = [];
Expand Down
56 changes: 26 additions & 30 deletions src/ConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@


use Akademiano\Utils\ArrayTools;
use Akademiano\Utils\DIContainerIncludeInterface;
use Akademiano\Utils\FileSystem;
use Akademiano\Utils\Parts\DIContainerTrait;
use Pimple\Container;

class ConfigLoader
class ConfigLoader implements DIContainerIncludeInterface
{
use DIContainerTrait;

const LOCAL_CONFIG = 'local';
const GLOBAL_CONFIG = 'global';
const AUTO_CONFIG = 'auto';
Expand Down Expand Up @@ -39,22 +43,6 @@ public function __construct(Container $diContainer, array $configDirs = null)
}
}

/**
* @return Container
*/
public function getDiContainer()
{
return $this->diContainer;
}

/**
* @param Container $diContainer
*/
public function setDiContainer(Container $diContainer)
{
$this->diContainer = $diContainer;
}

/**
* @param mixed $configDirs
*/
Expand All @@ -67,25 +55,33 @@ public function getConfigDirs()
{
if (null === $this->configDirs) {
$configDirs = [];
$diContainer = $this->getDiContainer();

if (empty($configDirs)) {
$appDir = $this->getDiContainer()["appDir"];
if (null !== $appDir) {
$configDirs[self::LEVEL_APP] = $appDir . DIRECTORY_SEPARATOR . self::CONFIG_DIR;
if (isset($diContainer["appDir"])) {
$appDir = $diContainer["appDir"];
if (null !== $appDir) {
$configDirs[self::LEVEL_APP] = $appDir . DIRECTORY_SEPARATOR . self::CONFIG_DIR;
}
}

$projectConfigDir = $this->getDiContainer()["sharedSiteDir"];
if (null !== $projectConfigDir) {
$dir = $projectConfigDir . DIRECTORY_SEPARATOR . "config";
if (is_dir($dir)) {
$configDirs[self::LEVEL_PROJECT] = $projectConfigDir . DIRECTORY_SEPARATOR . "config";
if (isset($diContainer["sharedSiteDir"])) {
$projectConfigDir = $diContainer["sharedSiteDir"];
if (null !== $projectConfigDir) {
$dir = $projectConfigDir . DIRECTORY_SEPARATOR . "config";
if (is_dir($dir)) {
$configDirs[self::LEVEL_PROJECT] = $projectConfigDir . DIRECTORY_SEPARATOR . "config";
}
}
}
$siteConfigDir = $this->getDiContainer()["currentSiteDir"];
if (null !== $siteConfigDir) {
$dir = $siteConfigDir . DIRECTORY_SEPARATOR . "config";
if (is_dir($dir)) {
$configDirs[self::LEVEL_SITE] = $dir;

if (isset($diContainer["currentSiteDir"])) {
$siteConfigDir = $diContainer["currentSiteDir"];
if (null !== $siteConfigDir) {
$dir = $siteConfigDir . DIRECTORY_SEPARATOR . "config";
if (is_dir($dir)) {
$configDirs[self::LEVEL_SITE] = $dir;
}
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/ConfigurableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ trait ConfigurableTrait
*/
public function getConfig($path = null, $default = null)
{
if (!$this->config instanceof Config) {
return is_array($default) ? new Config([]) : $default;;
}
if ($path) {
return $this->config->get($path, $default);
}
Expand All @@ -27,7 +24,7 @@ public function getConfig($path = null, $default = null)
/**
* @param Config $config
*/
public function setConfig($config)
public function setConfig(Config $config)
{
$this->config = $config;
}
Expand Down

0 comments on commit 24da12b

Please sign in to comment.