Use closure for error handling

This commit is contained in:
Andrea Marco Sartori
2022-10-29 18:28:21 +10:00
parent c72f4a6313
commit 1772eb3e37
2 changed files with 6 additions and 4 deletions

View File

@ -6,6 +6,7 @@ use Cerbero\JsonParser\Decoders\ArrayDecoder;
use Cerbero\JsonParser\Decoders\DecodedValue;
use Cerbero\JsonParser\Decoders\Decoder;
use Cerbero\JsonParser\Pointers\Pointer;
use Closure;
/**
* The configuration.
@ -37,9 +38,9 @@ class Config
/**
* The callback to run during a parsing error.
*
* @var callable
* @var Closure
*/
public callable $onError;
public Closure $onError;
/**
* Instantiate the class

View File

@ -6,6 +6,7 @@ use Cerbero\JsonParser\Decoders\Decoder;
use Cerbero\JsonParser\Decoders\ObjectDecoder;
use Cerbero\JsonParser\Pointers\Pointer;
use Cerbero\JsonParser\Sources\AnySource;
use Closure;
use IteratorAggregate;
use Traversable;
@ -114,10 +115,10 @@ class JsonParser implements IteratorAggregate
/**
* Set the logic to run during parsing errors
*
* @param callable $callback
* @param Closure $callback
* @return static
*/
public function onError(callable $callback): static
public function onError(Closure $callback): static
{
$this->config->onError = $callback;