| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\WikiPEG; |
| 4 |
|
| 5 |
class LocationRange implements \JsonSerializable { |
| 6 |
/** @var Location */ |
| 7 |
public $start; |
| 8 |
|
| 9 |
/** @var Location */ |
| 10 |
public $end; |
| 11 |
|
| 12 |
/** |
| 13 |
* @param int $startOffset |
| 14 |
* @param int $startLine |
| 15 |
* @param int $startColumn |
| 16 |
* @param int $endOffset |
| 17 |
* @param int $endLine |
| 18 |
* @param int $endColumn |
| 19 |
*/ |
| 20 |
public function __construct( $startOffset, $startLine, $startColumn, $endOffset, $endLine, $endColumn ) { |
| 21 |
$this->start = new Location( $startOffset, $startLine, $startColumn ); |
| 22 |
$this->end = new Location( $endOffset, $endLine, $endColumn ); |
| 23 |
} |
| 24 |
|
| 25 |
/** @return string */ |
| 26 |
public function __toString() { |
| 27 |
return "{$this->start}-{$this->end}"; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Emit a JSON serialization similar to JS, for testing |
| 32 |
* @return array |
| 33 |
*/ |
| 34 |
#[\ReturnTypeWillChange] |
| 35 |
public function jsonSerialize(): array { |
| 36 |
return [ |
| 37 |
'start' => $this->start, |
| 38 |
'end' => $this->end, |
| 39 |
]; |
| 40 |
} |
| 41 |
} |