1<?php 2 3namespace dokuwiki\plugin\prosemirror\schema; 4 5/** 6 * Class Mark 7 * 8 * @package dokuwiki\plugin\prosemirror\schema 9 * @link http://prosemirror.net/ref.html#model.Mark 10 */ 11class Mark implements \JsonSerializable 12{ 13 /** @var string The type of this mark */ 14 protected $type; 15 16 /** @var array The attributes associated with this mark */ 17 protected $attrs = []; 18 19 /** 20 * Mark constructor. 21 * 22 * @param string $type 23 */ 24 public function __construct($type) 25 { 26 $this->type = $type; 27 } 28 29 /** 30 * @param string $key Attribute key to get or set 31 * @param null $value Attribute value to set, null to get 32 * 33 * @return $this|mixed Either the wanted value or the Mark itself 34 */ 35 public function attr($key, $value = null) 36 { 37 if (is_null($value)) { 38 if (isset($this->attrs[$key])) { 39 return $this->attrs[$key]; 40 } else { 41 return null; 42 } 43 } 44 45 $this->attrs[$key] = $value; 46 return $this; 47 } 48 49 /** 50 * Specify data which should be serialized to JSON 51 * 52 * @link http://php.net/manual/en/jsonserializable.jsonserialize.php 53 * @return mixed data which can be serialized by <b>json_encode</b>, 54 * which is a value of any type other than a resource. 55 * @since 5.4.0 56 */ 57 public function jsonSerialize() 58 { 59 $json = [ 60 'type' => $this->type, 61 ]; 62 if ($this->attrs) { 63 $json['attrs'] = $this->attrs; 64 } 65 66 return $json; 67 } 68} 69