mirror of
https://github.com/cerbero90/json-parser.git
synced 2025-01-17 13:08:16 +01:00
Refine callable pointers
This commit is contained in:
parent
6d731cdb51
commit
45ed8e9650
@ -67,10 +67,11 @@ final class Parser implements IteratorAggregate
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->state->hasBuffer() && $this->state->inObject()) {
|
||||
yield $this->decoder->decode($this->state->key()) => $this->decoder->decode($this->state->value());
|
||||
} elseif ($this->state->hasBuffer() && !$this->state->inObject()) {
|
||||
yield $this->decoder->decode($this->state->value());
|
||||
if ($this->state->hasBuffer()) {
|
||||
$key = $this->decoder->decode($this->state->key());
|
||||
$value = $this->decoder->decode($this->state->value());
|
||||
|
||||
yield $key => $this->state->callPointer($value, $key);
|
||||
}
|
||||
|
||||
if ($this->state->canStopParsing()) {
|
||||
|
@ -100,7 +100,7 @@ final class Pointer implements Stringable
|
||||
*/
|
||||
public function call(mixed $value, mixed $key): mixed
|
||||
{
|
||||
return call_user_func($this->callback, $value, $key);
|
||||
return call_user_func($this->callback, $value, $key) ?? $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,6 +124,18 @@ final class State
|
||||
return $this->pointers->wereFound() && !$this->pointer->includesTree($this->tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the current pointer callback
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function callPointer(mixed $value, mixed $key): mixed
|
||||
{
|
||||
return $this->pointer->call($value, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutate state depending on the given token
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user