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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->state->hasBuffer() && $this->state->inObject()) {
|
if ($this->state->hasBuffer()) {
|
||||||
yield $this->decoder->decode($this->state->key()) => $this->decoder->decode($this->state->value());
|
$key = $this->decoder->decode($this->state->key());
|
||||||
} elseif ($this->state->hasBuffer() && !$this->state->inObject()) {
|
$value = $this->decoder->decode($this->state->value());
|
||||||
yield $this->decoder->decode($this->state->value());
|
|
||||||
|
yield $key => $this->state->callPointer($value, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->state->canStopParsing()) {
|
if ($this->state->canStopParsing()) {
|
||||||
|
@ -100,7 +100,7 @@ final class Pointer implements Stringable
|
|||||||
*/
|
*/
|
||||||
public function call(mixed $value, mixed $key): mixed
|
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);
|
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
|
* Mutate state depending on the given token
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user