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 json_encode, * 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; } }