Submit
Path:
~
/
/
usr
/
local
/
psa
/
admin
/
plib
/
modules
/
wp-toolkit
/
vendor
/
cerbero
/
json-parser
/
src
/
ValueObjects
/
File Content:
State.php
<?php namespace WPToolkitDependenciesIsolationPrefix\Cerbero\JsonParser\ValueObjects; use WPToolkitDependenciesIsolationPrefix\Cerbero\JsonParser\Pointers\Pointers; use WPToolkitDependenciesIsolationPrefix\Cerbero\JsonParser\Tokens\CompoundBegin; use WPToolkitDependenciesIsolationPrefix\Cerbero\JsonParser\Tokens\Parser; use WPToolkitDependenciesIsolationPrefix\Cerbero\JsonParser\Tokens\Token; use WPToolkitDependenciesIsolationPrefix\Cerbero\JsonParser\Tokens\Tokens; use Closure; /** * The JSON parsing state. * */ final class State { /** * The JSON tree. * * @var Tree */ public readonly Tree $tree; /** * The JSON buffer. * * @var Parser|string */ private Parser|string $buffer = ''; /** * Whether an object key is expected. * * @var bool */ public bool $expectsKey = \false; /** * The expected token. * * @var int */ public int $expectedToken = Tokens::COMPOUND_BEGIN; /** * Instantiate the class. * * @param Pointers $pointers * @param Closure $lazyLoad */ public function __construct(private readonly Pointers $pointers, private readonly Closure $lazyLoad) { $this->tree = new Tree($pointers); } /** * Determine whether the parser can stop parsing * * @return bool */ public function canStopParsing() : bool { return $this->pointers->wereFoundInTree($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->pointers->matching()->call($value, $key); } /** * Mutate state depending on the given token * * @param Token $token * @return void */ public function mutateByToken(Token $token) : void { $this->tree->traverseToken($token, $this->expectsKey); if ($this->tree->isMatched() && (!$this->expectsKey && $token->isValue() || $this->tree->isDeep())) { $pointer = $this->pointers->markAsFound(); if ($token instanceof CompoundBegin && $pointer->isLazy) { $this->buffer = ($this->lazyLoad)(); $token->shouldLazyLoad = \true; } else { /** @phpstan-ignore-next-line */ $this->buffer .= $token; } } $token->mutateState($this); } /** * Determine whether the buffer contains tokens * * @return bool */ public function hasBuffer() : bool { return $this->buffer != ''; } /** * Retrieve the value from the buffer and reset it * * @return Parser|string */ public function value() : Parser|string { $buffer = $this->buffer; $this->buffer = ''; return $buffer; } }
Edit
Rename
Chmod
Delete
FILE
FOLDER
INFO
Name
Size
Permission
Action
Config.php
2292 bytes
0644
Progress.php
1864 bytes
0644
State.php
2954 bytes
0644
Tree.php
4778 bytes
0644
N4ST4R_ID | Naxtarrr