mirror of
https://github.com/halaxa/json-machine.git
synced 2025-03-15 17:09:39 +01:00
Deprecated Decoder interface and co.
This commit is contained in:
parent
3dcaa27108
commit
8cdfe92ae7
@ -3,7 +3,8 @@
|
||||
## master
|
||||
|
||||
### Changed
|
||||
- `JsonMachine` entry point class is deprecated, use `Items` instead.
|
||||
- `JsonMachine\JsonMachine` entry point class is deprecated, use `JsonMachine\Items` instead.
|
||||
- `JsonMachine\JsonDecoder\Decoder` interface is deprecated. Use `JsonMachine\JsonDecoder\ChunkDecoder` instead.
|
||||
|
||||
### Added
|
||||
- New entry point class `Items` replaces `JsonMachine`.
|
||||
|
14
src/JsonDecoder/ChunkDecoder.php
Normal file
14
src/JsonDecoder/ChunkDecoder.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace JsonMachine\JsonDecoder;
|
||||
|
||||
|
||||
interface ChunkDecoder
|
||||
{
|
||||
public function decodeInternalKey($jsonScalarKey): ChunkDecodingStringResult;
|
||||
|
||||
public function decodeKey($jsonScalarKey): ChunkDecodingResult;
|
||||
|
||||
public function decodeValue($jsonValue): ChunkDecodingResult;
|
||||
}
|
49
src/JsonDecoder/ChunkDecodingResult.php
Normal file
49
src/JsonDecoder/ChunkDecodingResult.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace JsonMachine\JsonDecoder;
|
||||
|
||||
class ChunkDecodingResult
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isOk;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $errorMessage;
|
||||
|
||||
public function __construct(bool $isOk, $value, string $errorMessage = null)
|
||||
{
|
||||
$this->isOk = $isOk;
|
||||
$this->value = $value;
|
||||
$this->errorMessage = $errorMessage;
|
||||
}
|
||||
|
||||
public function isOk(): bool
|
||||
{
|
||||
return $this->isOk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getErrorMessage()
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
}
|
46
src/JsonDecoder/ChunkDecodingStringResult.php
Normal file
46
src/JsonDecoder/ChunkDecodingStringResult.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace JsonMachine\JsonDecoder;
|
||||
|
||||
class ChunkDecodingStringResult
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isOk;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $errorMessage;
|
||||
|
||||
public function __construct(bool $isOk, string $value, string $errorMessage = null)
|
||||
{
|
||||
$this->isOk = $isOk;
|
||||
$this->value = $value;
|
||||
$this->errorMessage = $errorMessage;
|
||||
}
|
||||
|
||||
public function isOk(): bool
|
||||
{
|
||||
return $this->isOk;
|
||||
}
|
||||
|
||||
public function getValue(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getErrorMessage()
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
}
|
@ -2,6 +2,15 @@
|
||||
|
||||
namespace JsonMachine\JsonDecoder;
|
||||
|
||||
@trigger_error(sprintf(
|
||||
'Interface %s is deprecated. Use %s instead.',
|
||||
Decoder::class,
|
||||
ChunkDecoder::class
|
||||
), E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @deprecated Use ChunkDecoder instead.
|
||||
*/
|
||||
interface Decoder
|
||||
{
|
||||
/**
|
||||
|
@ -2,6 +2,15 @@
|
||||
|
||||
namespace JsonMachine\JsonDecoder;
|
||||
|
||||
@trigger_error(sprintf(
|
||||
'Class %s is deprecated. Use %s instead.',
|
||||
DecodingResult::class,
|
||||
ChunkDecodingResult::class
|
||||
), E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @deprecated Use ChunkDecodingResult instead.
|
||||
*/
|
||||
class DecodingResult
|
||||
{
|
||||
private $isOk;
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace JsonMachine;
|
||||
|
||||
use JsonMachine\JsonDecoder\ChunkDecoder;
|
||||
use JsonMachine\JsonDecoder\Decoder;
|
||||
use JsonMachine\JsonDecoder\ExtJsonDecoder;
|
||||
|
||||
@ -21,7 +22,7 @@ class JsonMachine implements \IteratorAggregate, PositionAware
|
||||
private $jsonPointer;
|
||||
|
||||
/**
|
||||
* @var Decoder|null
|
||||
* @var Decoder|ChunkDecoder|null
|
||||
*/
|
||||
private $jsonDecoder;
|
||||
|
||||
@ -38,7 +39,7 @@ class JsonMachine implements \IteratorAggregate, PositionAware
|
||||
/**
|
||||
* @param iterable $bytesIterator
|
||||
* @param string $jsonPointer
|
||||
* @param Decoder $jsonDecoder
|
||||
* @param Decoder|ChunkDecoder $jsonDecoder
|
||||
* @param bool $debugEnabled
|
||||
* @throws Exception\InvalidArgumentException
|
||||
*/
|
||||
@ -64,7 +65,7 @@ class JsonMachine implements \IteratorAggregate, PositionAware
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string $jsonPointer
|
||||
* @param Decoder $jsonDecoder
|
||||
* @param Decoder|ChunkDecoder $jsonDecoder
|
||||
* @param bool $debugEnabled
|
||||
* @return self
|
||||
* @throws Exception\InvalidArgumentException
|
||||
@ -77,7 +78,7 @@ class JsonMachine implements \IteratorAggregate, PositionAware
|
||||
/**
|
||||
* @param string $file
|
||||
* @param string $jsonPointer
|
||||
* @param Decoder $jsonDecoder
|
||||
* @param Decoder|ChunkDecoder $jsonDecoder
|
||||
* @param bool $debugEnabled
|
||||
* @return self
|
||||
* @throws Exception\InvalidArgumentException
|
||||
@ -90,7 +91,7 @@ class JsonMachine implements \IteratorAggregate, PositionAware
|
||||
/**
|
||||
* @param resource $stream
|
||||
* @param string $jsonPointer
|
||||
* @param Decoder $jsonDecoder
|
||||
* @param Decoder|ChunkDecoder $jsonDecoder
|
||||
* @param bool $debugEnabled
|
||||
* @return self
|
||||
* @throws Exception\InvalidArgumentException
|
||||
@ -103,7 +104,7 @@ class JsonMachine implements \IteratorAggregate, PositionAware
|
||||
/**
|
||||
* @param iterable $iterable
|
||||
* @param string $jsonPointer
|
||||
* @param Decoder $jsonDecoder
|
||||
* @param Decoder|ChunkDecoder $jsonDecoder
|
||||
* @param bool $debugEnabled
|
||||
* @return self
|
||||
* @throws Exception\InvalidArgumentException
|
||||
|
@ -7,6 +7,7 @@ use JsonMachine\Exception\JsonMachineException;
|
||||
use JsonMachine\Exception\PathNotFoundException;
|
||||
use JsonMachine\Exception\SyntaxError;
|
||||
use JsonMachine\Exception\UnexpectedEndSyntaxErrorException;
|
||||
use JsonMachine\JsonDecoder\ChunkDecoder;
|
||||
use JsonMachine\JsonDecoder\Decoder;
|
||||
use JsonMachine\JsonDecoder\ExtJsonDecoder;
|
||||
use Traversable;
|
||||
@ -38,13 +39,13 @@ class Parser implements \IteratorAggregate, PositionAware
|
||||
/** @var string */
|
||||
private $jsonPointer;
|
||||
|
||||
/** @var Decoder */
|
||||
/** @var Decoder|ChunkDecoder */
|
||||
private $jsonDecoder;
|
||||
|
||||
/**
|
||||
* @param Traversable $lexer
|
||||
* @param string $jsonPointer Follows json pointer RFC https://tools.ietf.org/html/rfc6901
|
||||
* @param Decoder $jsonDecoder
|
||||
* @param Decoder|ChunkDecoder $jsonDecoder
|
||||
*/
|
||||
public function __construct(Traversable $lexer, $jsonPointer = '', $jsonDecoder = null)
|
||||
{
|
||||
@ -152,7 +153,11 @@ class Parser implements \IteratorAggregate, PositionAware
|
||||
$key = $token;
|
||||
} elseif ($currentLevel < $iteratorLevel) {
|
||||
$key = $token;
|
||||
$keyResult = $this->jsonDecoder->decodeKey($token);
|
||||
if ($this->jsonDecoder instanceof ChunkDecoder) {
|
||||
$keyResult = $this->jsonDecoder->decodeInternalKey($token);
|
||||
} else {
|
||||
$keyResult = $this->jsonDecoder->decodeKey($token);
|
||||
}
|
||||
if (! $keyResult->isOk()) {
|
||||
$this->error($keyResult->getErrorMessage(), $token);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user