mirror of
https://github.com/halaxa/json-machine.git
synced 2025-03-15 17:09:39 +01:00
Added 'recursive' option
This commit is contained in:
parent
1466ddbf02
commit
e21abf9342
@ -63,7 +63,8 @@ final class Items implements \IteratorAggregate, PositionAware
|
||||
$this->chunks
|
||||
),
|
||||
$this->jsonPointer,
|
||||
$this->jsonDecoder ?: new ExtJsonDecoder()
|
||||
$this->jsonDecoder ?: new ExtJsonDecoder(),
|
||||
$options['recursive']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -66,12 +66,18 @@ class ItemsOptions extends \ArrayObject
|
||||
return $debug;
|
||||
}
|
||||
|
||||
private function opt_recursive(bool $recursive)
|
||||
{
|
||||
return $recursive;
|
||||
}
|
||||
|
||||
public static function defaultOptions(): array
|
||||
{
|
||||
return [
|
||||
'pointer' => '',
|
||||
'decoder' => new ExtJsonDecoder(),
|
||||
'debug' => false,
|
||||
'recursive' => false,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ class ItemsOptionsTest extends TestCase
|
||||
'pointer' => '',
|
||||
'decoder' => new ExtJsonDecoder(),
|
||||
'debug' => false,
|
||||
'recursive' => false,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ namespace JsonMachineTest;
|
||||
|
||||
use JsonMachine\Items;
|
||||
use JsonMachine\JsonDecoder\PassThruDecoder;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* @covers \JsonMachine\Items
|
||||
@ -139,4 +140,16 @@ class ItemsTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertSame(['/one', '/two'], $items->getJsonPointers());
|
||||
}
|
||||
|
||||
public function testRecursiveIteration()
|
||||
{
|
||||
$items = Items::fromString('[[":)"]]', ['recursive' => true]);
|
||||
|
||||
foreach ($items as $emojis) {
|
||||
$this->assertInstanceOf(Traversable::class, $emojis);
|
||||
foreach ($emojis as $emoji) {
|
||||
$this->assertSame(":)", $emoji);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user