Skip to content

Commit

Permalink
json info in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
vasiliishvakin committed Sep 4, 2017
1 parent a5ddd30 commit f7e22d9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Akademiano\Utils\Parts\DIContainerTrait;
use Pimple\Container;

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

Expand Down Expand Up @@ -41,7 +41,7 @@ public function set($data, array $path = null)
$this->childConfig = [];

if (is_null($path)) {
$this->configRaw = (array) $data;
$this->configRaw = (array)$data;
return;
}
$this->configRaw = ArrayTools::set($this->configRaw, $path, $data);
Expand All @@ -52,7 +52,7 @@ public function joinLeft($data)
if ($data instanceof Config) {
$data = $data->toArray();
} else {
$data = (array) $data;
$data = (array)$data;
}
$this->configRaw = ArrayTools::mergeRecursive($data, $this->configRaw);
$this->childConfig = [];
Expand All @@ -64,7 +64,7 @@ public function joinRight($data)
if ($data instanceof Config) {
$data = $data->toArray();
} else {
$data = (array) $data;
$data = (array)$data;
}
$this->configRaw = ArrayTools::mergeRecursive($this->configRaw, $data);
$this->childConfig = [];
Expand All @@ -81,7 +81,7 @@ public function get($path = null, $default = null)
if (is_null($path)) {
return $this;
}
$pathKey = implode('|', (array) $path);
$pathKey = implode('|', (array)$path);
if (!isset($this->childConfig[$pathKey])) {
if (!ArrayTools::issetByPath($this->configRaw, $path)) {
return is_array($default) && !is_callable($default) ? new Config($default, $this->getDiContainer()) : $default;
Expand All @@ -108,19 +108,25 @@ public function getAndCall($path, $callback, array $arguments = null)
$value = $this->get($path);
if (null !== $arguments) {
array_unshift($arguments, $value);
}
else {
} else {
$arguments = [$value];
}
return call_user_func_array($callback, $arguments);
}
throw new \Exception(sprintf(
'In config not found path \'%s\'',
is_scalar($path) ? $path : json_encode($path, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK)
));
}

public function getOrThrow($path)
{
$data = $this->get($path);
if (null === $data) {
throw new \Exception("$path not found in config");
throw new \Exception(sprintf(
'In config not found path \'%s\'',
is_scalar($path) ? $path : json_encode($path, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK)
));
}
return $data;
}
Expand Down

0 comments on commit f7e22d9

Please sign in to comment.