Skip to content

Commit

Permalink
IniAdapter, NeonAdapter: process() is public [Closes #134]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 22, 2016
1 parent 4a1140c commit 7481551
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/DI/Config/Adapters/IniAdapter.php
Expand Up @@ -38,9 +38,18 @@ public function load($file)
$error = error_get_last();
throw new Nette\InvalidStateException("parse_ini_file(): $error[message]");
}
return $this->process($ini);
}


/**
* @return array
* @throws Nette\InvalidStateException
*/
public function process(array $arr)
{
$data = [];
foreach ($ini as $secName => $secData) {
foreach ($arr as $secName => $secData) {
if (is_array($secData)) { // is section?
if (substr($secName, -1) === self::RAW_SECTION) {
$secName = substr($secName, 0, -1);
Expand All @@ -54,7 +63,7 @@ public function load($file)
if (!isset($cursor[$part]) || is_array($cursor[$part])) {
$cursor = & $cursor[$part];
} else {
throw new Nette\InvalidStateException("Invalid key '$key' in section [$secName] in file '$file'.");
throw new Nette\InvalidStateException("Invalid key '$key' in section [$secName].");
}
}
$cursor = $val;
Expand All @@ -74,7 +83,7 @@ public function load($file)
if (!isset($cursor[$part]) || is_array($cursor[$part])) {
$cursor = & $cursor[$part];
} else {
throw new Nette\InvalidStateException("Invalid section [$secName] in file '$file'.");
throw new Nette\InvalidStateException("Invalid section [$secName].");
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/DI/Config/Adapters/NeonAdapter.php
Expand Up @@ -35,7 +35,11 @@ public function load($file)
}


private function process(array $arr)
/**
* @return array
* @throws Nette\InvalidStateException
*/
public function process(array $arr)
{
$res = [];
foreach ($arr as $key => $val) {
Expand Down
4 changes: 2 additions & 2 deletions tests/DI/IniAdapter.errors.phpt
Expand Up @@ -14,13 +14,13 @@ require __DIR__ . '/../bootstrap.php';
Assert::exception(function () {
$config = new Config\Loader;
$config->load('files/iniAdapter.scalar1.ini');
}, Nette\InvalidStateException::class, "Invalid section [scalar.set] in file '%a%'.");
}, Nette\InvalidStateException::class, "Invalid section [scalar.set].");


Assert::exception(function () {
$config = new Config\Loader;
$config->load('files/iniAdapter.scalar2.ini');
}, Nette\InvalidStateException::class, "Invalid key 'date.timezone' in section [set] in file '%a%'.");
}, Nette\InvalidStateException::class, "Invalid key 'date.timezone' in section [set].");


Assert::exception(function () {
Expand Down

0 comments on commit 7481551

Please sign in to comment.