Skip to content

Commit

Permalink
Merge pull request #5 from maschmann/maschmann-patch-1
Browse files Browse the repository at this point in the history
Fixed directory for includes
  • Loading branch information
maschmann committed Apr 27, 2015
2 parents 63b3747 + 5511229 commit 7c3a27d
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Config/AbstractConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ abstract class AbstractConfig extends Data
*/
protected $filecheck = true;

/**
* @var string
*/
private $currentBasepath;

/**
* @var array
*/
Expand Down Expand Up @@ -72,6 +77,8 @@ public function addConfig($name, $file)
*/
public function readConfig($file)
{
$this->currentBasepath = dirname($file);

$config = $this->readFile($file);
$config = $this->extractImports($config);
$config = $this->extractDefault($config);
Expand Down Expand Up @@ -127,9 +134,11 @@ private function extractImports(array $config)
$this->imports = [];
foreach ($config['imports'] as $key => $import) {
if (false === empty($import['resource'])) {
$include = $this->checkPath($import['resource']);

$this->imports = array_replace_recursive(
$this->imports,
$this->readFile($import['resource'])
$this->readFile($include)
);
}
}
Expand Down Expand Up @@ -163,4 +172,19 @@ private function mergeDefault()
{
$this->default = array_replace_recursive($this->imports, $this->default);
}

/**
* Only add basepath if not already in filename.
*
* @param string $include
* @return string
*/
private function checkPath($include)
{
if (0 !== strpos($include, $this->currentBasepath)) {
$include = $this->currentBasepath . '/' . $include;
}

return $include;
}
}

0 comments on commit 7c3a27d

Please sign in to comment.