Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
Add option to retrieve an array from an item
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Sep 29, 2017
1 parent 9ff54f0 commit 12700eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public function getChildren(array $default = null) : TreeReader
return new TreeReader($this->getValue('array', $default), $this->key, ...$this->parentKeys);
}

public function getArray(array $default = null) : array
{
return $this->getValue('array', $default);
}

private function getValue(string $expectedType, $default)
{
if (null === $this->value && null !== $default) {
Expand Down
5 changes: 5 additions & 0 deletions src/TreeReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public function getChildren(string $key, array $default = null) : self
return $this->getItem($key, $default)->getChildren();
}

public function getArray(string $key, array $default = null) : array
{
return $this->getItem($key, $default)->getArray();
}

private function getItem(string $key, $default)
{
if ($this->hasNonNullValue($key)) {
Expand Down
5 changes: 5 additions & 0 deletions test/TreeReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public function scalarGetterProvider()
true,
false,
],
[
'getArray',
['baz' => 'bat'],
['bat' => 'baz'],
],
];
}

Expand Down

0 comments on commit 12700eb

Please sign in to comment.