| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\DiscussionTools\ThreadItem; |
| 4 |
|
| 5 |
trait ThreadItemTrait { |
| 6 |
|
| 7 |
|
| 8 |
abstract public function getId(): string; |
| 9 |
abstract public function getType(): string; |
| 10 |
abstract public function getReplies(): array; |
| 11 |
abstract public function getLevel(): int; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public function jsonSerialize( bool $deep = false, ?callable $callback = null ): array { |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
$array = [ |
| 26 |
'type' => $this->getType(), |
| 27 |
'level' => $this->getLevel(), |
| 28 |
'id' => $this->getId(), |
| 29 |
'replies' => array_map( static function ( ThreadItem $comment ) use ( $deep, $callback ) { |
| 30 |
return $deep ? $comment->jsonSerialize( $deep, $callback ) : $comment->getId(); |
| 31 |
}, $this->getReplies() ) |
| 32 |
]; |
| 33 |
if ( $callback ) { |
| 34 |
$callback( $array, $this ); |
| 35 |
} |
| 36 |
return $array; |
| 37 |
} |
| 38 |
} |