55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
namespace ContentNation\ActivityPub\Common;
|
|
require_once("APObject.php");
|
|
class Collection extends APObject {
|
|
protected int $totalItems = 0;
|
|
private string $first = '';
|
|
private string $last = '';
|
|
|
|
public function __construct() {
|
|
parent::__construct('Collection');
|
|
parent::addContext('https://www.w3.org/ns/activitystreams');
|
|
}
|
|
|
|
/**
|
|
* convert internal state to php array
|
|
* @return array<string,mixed>
|
|
*/
|
|
public function toObject() {
|
|
$return = parent::toObject();
|
|
$return['type'] = 'Collection';
|
|
if ($this->totalItems > 0) {
|
|
$return['totalItems'] = $this->totalItems;
|
|
}
|
|
if ($this->first !== '') {
|
|
$return['first'] = $this->first;
|
|
}
|
|
if ($this->last !== '') {
|
|
$return['last'] = $this->last;
|
|
}
|
|
return $return;
|
|
}
|
|
|
|
/**
|
|
* create object from json
|
|
* @param array<string,mixed> $json input json
|
|
* @return bool true on success
|
|
*/
|
|
public function fromJson($json) : bool {
|
|
return parent::fromJson($json);
|
|
}
|
|
|
|
public function count() : int {
|
|
return $this->totalItems;
|
|
}
|
|
|
|
public function setFirst(string $url) : void {
|
|
$this->first = $url;
|
|
}
|
|
|
|
public function setLast(string $url) : void {
|
|
$this->last = $url;
|
|
}
|
|
|
|
}
|