forked from cosmocode/dokuwiki-plugin-prosemirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMark.php
69 lines (60 loc) · 1.54 KB
/
Mark.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
<?php
namespace dokuwiki\plugin\prosemirror\schema;
/**
* Class Mark
*
* @package dokuwiki\plugin\prosemirror\schema
* @link http://prosemirror.net/ref.html#model.Mark
*/
class Mark implements \JsonSerializable
{
/** @var string The type of this mark */
protected $type;
/** @var array The attributes associated with this mark */
protected $attrs = [];
/**
* Mark constructor.
*
* @param string $type
*/
public function __construct($type)
{
$this->type = $type;
}
/**
* @param string $key Attribute key to get or set
* @param null $value Attribute value to set, null to get
*
* @return $this|mixed Either the wanted value or the Mark itself
*/
public function attr($key, $value = null)
{
if (is_null($value)) {
if (isset($this->attrs[$key])) {
return $this->attrs[$key];
} else {
return null;
}
}
$this->attrs[$key] = $value;
return $this;
}
/**
* Specify data which should be serialized to JSON
*
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
function jsonSerialize()
{
$json = [
'type' => $this->type,
];
if ($this->attrs) {
$json['attrs'] = $this->attrs;
}
return $json;
}
}