| 1 |
<?php |
| 2 |
declare( strict_types = 1 ); |
| 3 |
|
| 4 |
namespace Wikimedia\Parsoid\NodeData; |
| 5 |
|
| 6 |
use Wikimedia\JsonCodec\JsonCodecable; |
| 7 |
use Wikimedia\JsonCodec\JsonCodecableTrait; |
| 8 |
use Wikimedia\Parsoid\Tokens\KVSourceRange; |
| 9 |
|
| 10 |
class ParamInfo implements JsonCodecable { |
| 11 |
use JsonCodecableTrait; |
| 12 |
|
| 13 |
/** |
| 14 |
* The parameter key |
| 15 |
*/ |
| 16 |
public string $k; |
| 17 |
|
| 18 |
/** |
| 19 |
* The key source wikitext, if different from $k |
| 20 |
*/ |
| 21 |
public ?string $keyWt = null; |
| 22 |
|
| 23 |
/** |
| 24 |
* The parameter value source wikitext |
| 25 |
*/ |
| 26 |
public ?string $valueWt = null; |
| 27 |
|
| 28 |
public ?KVSourceRange $srcOffsets = null; |
| 29 |
|
| 30 |
public bool $named = false; |
| 31 |
|
| 32 |
/** |
| 33 |
* @var string[]|null |
| 34 |
*/ |
| 35 |
public ?array $spc = null; |
| 36 |
|
| 37 |
public ?string $html = null; |
| 38 |
|
| 39 |
public function __construct( string $key, ?KVSourceRange $srcOffsets = null ) { |
| 40 |
$this->k = $key; |
| 41 |
$this->srcOffsets = $srcOffsets; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Create an object from unserialized data-parsoid.pi |
| 46 |
* @param array $data |
| 47 |
* @return self |
| 48 |
*/ |
| 49 |
public static function newFromJsonArray( array $data ): ParamInfo { |
| 50 |
$info = new self( $data['k'] ?? '' ); |
| 51 |
$info->named = $data['named'] ?? false; |
| 52 |
$info->spc = $data['spc'] ?? null; |
| 53 |
return $info; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Serialize for data-parsoid.pi. The rest of the data is temporary, it is |
| 58 |
* not needed across requests. |
| 59 |
* |
| 60 |
* @return array |
| 61 |
*/ |
| 62 |
public function toJsonArray(): array { |
| 63 |
$ret = [ 'k' => $this->k ]; |
| 64 |
if ( $this->named ) { |
| 65 |
$ret['named'] = true; |
| 66 |
} |
| 67 |
if ( $this->spc ) { |
| 68 |
$ret['spc'] = $this->spc; |
| 69 |
} |
| 70 |
return $ret; |
| 71 |
} |
| 72 |
} |