Skip to content

Commit

Permalink
Do not add config dirs with same paths (only add if new lever in bigg…
Browse files Browse the repository at this point in the history
…er).
  • Loading branch information
vasiliishvakin committed May 21, 2017
1 parent f953644 commit a5b1583
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/ConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class ConfigLoader implements DIContainerIncludeInterface

protected $configDirs = [];

protected $settedPaths = [];

/** @var Config[] */
protected $config = [];

Expand All @@ -42,7 +44,6 @@ public function __construct(Container $diContainer = null)
}
}


public function setConfigDirs(array $paths, $level = null)
{
$this->levels = [];
Expand All @@ -56,19 +57,41 @@ public function setConfigDirs(array $paths, $level = null)

public function addConfigDir($path, $level = ConfigDir::LEVEL_DEFAULT, array $params = null)
{
if (array_key_exists($path, $this->settedPaths)) {
if ($this->settedPaths[$path] >= $level) {
return;
} else {
unset($this->settedPaths[$path]);
}
}

$this->paths[$level][$path] = $path;
$this->levels[$level] = $level;
$this->params[$level][$path] = $params;
$this->config = [];
$this->settedPaths[$path] = $level;
}

public function attachConfigDir(ConfigDir $dir, $level = null)
{
if (null !== $level) {
$dir->setLevel($level);
}
$this->configDirs[$dir->getLevel()][$dir->getPath()] = $dir;

$level = $dir->getLevel();
$path = $dir->getPath();

if (array_key_exists($path, $this->settedPaths)) {
if ($this->settedPaths[$path] >= $level) {
return;
} else {
unset($this->settedPaths[$path]);
}
}

$this->configDirs[$level][$path] = $dir;
$this->levels[$level] = $level;
$this->settedPaths[$path] = $level;
}

public function getLevels()
Expand Down Expand Up @@ -116,7 +139,8 @@ public function getConfigDirs($level)
if (!FileSystem::inDir($this->getRootDir(), $path)) {
throw new PathRestrictException('Path %s not in Root Path', $path);
}
$this->configDirs[$level][$path] = new ConfigDir($path, $level, $params);
$dir = new ConfigDir($path, $level, $params);
$this->configDirs[$level][$dir->getPath()] = $dir;
}
}
unset($this->paths[$level]);
Expand Down

0 comments on commit a5b1583

Please sign in to comment.