wiki.techinc.nl/tests/phpunit/mocks/json/JsonUnserializableSubClass.php
Petr Pchelko 7c68ae9296 Safe ParserOutput extension data and JsonUnserializable helper.
One major difference with what we've had before is that now we
actually write class names into the serialization - given that
this new mechanism is extencible, we can't establish any kind
of mapping of allowed classes. I do not think it's a problem
though.

Bug: T264394
Change-Id: Ia152f3b76b967aabde2d8a182e3aec7d3002e5ea
2020-11-10 11:21:09 -07:00

35 lines
919 B
PHP

<?php
namespace MediaWiki\Tests\Json;
use MediaWiki\Json\JsonUnserializableTrait;
use MediaWiki\Json\JsonUnserializer;
/**
* Testing class for JsonUnserializer unit tests.
* @package MediaWiki\Tests\Json
*/
class JsonUnserializableSubClass extends JsonUnserializableSuperClass {
use JsonUnserializableTrait;
private $subClassField;
public function __construct( string $superClassFieldValue, string $subClassFieldValue ) {
parent::__construct( $superClassFieldValue );
$this->subClassField = $subClassFieldValue;
}
public function getSubClassField(): string {
return $this->subClassField;
}
public static function newFromJsonArray( JsonUnserializer $unserializer, array $json ) {
return new self( $json['super_class_field'], $json['sub_class_field'] );
}
protected function toJsonArray(): array {
return parent::toJsonArray() + [
'sub_class_field' => $this->getSubClassField()
];
}
}