-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathFacadeTrait.php
80 lines (66 loc) · 1.76 KB
/
FacadeTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
declare(strict_types=1);
namespace JsonMachine;
use JsonMachine\Exception\InvalidArgumentException;
use JsonMachine\JsonDecoder\ExtJsonDecoder;
use LogicException;
trait FacadeTrait
{
/**
* @var Parser
*/
private $parser;
/**
* @var bool
*/
private $debugEnabled;
public function isDebugEnabled(): bool
{
return $this->debugEnabled;
}
/**
* @throws InvalidArgumentException
*/
private static function createParser(iterable $bytesIterator, ItemsOptions $options, bool $recursive): Parser
{
if ($options['debug']) {
$tokensClass = TokensWithDebugging::class;
} else {
$tokensClass = Tokens::class;
}
return new Parser(
new $tokensClass(
$bytesIterator
),
$options['pointer'],
$options['decoder'] ?: new ExtJsonDecoder(),
$recursive
);
}
/**
* Returns JSON bytes read so far.
*/
public function getPosition()
{
if ($this->parser instanceof PositionAware) {
return $this->parser->getPosition();
}
throw new LogicException('getPosition() may only be called on PositionAware');
}
/**
* @param string $string
*/
abstract public static function fromString($string, array $options = []): self;
/**
* @param string $file
*/
abstract public static function fromFile($file, array $options = []): self;
/**
* @param resource $stream
*/
abstract public static function fromStream($stream, array $options = []): self;
/**
* @param iterable $iterable
*/
abstract public static function fromIterable($iterable, array $options = []): self;
}