Created
August 11, 2020 18:17
-
-
Save glaphire/63ef6738c1e70a228a60ab22b39698c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Pagination; | |
use JsonSerializable; | |
class PaginatedCollection implements JsonSerializable | |
{ | |
private $items; | |
private $total; | |
private $count; | |
private $links = []; | |
public function __construct($items, $totalItems) | |
{ | |
$this->items = $items; | |
$this->total = $totalItems; | |
$this->count = count($items); | |
} | |
public function addLink($ref, $url) | |
{ | |
$this->links[$ref] = $url; | |
} | |
public function jsonSerialize() | |
{ | |
return [ | |
'items' => $this->items, | |
'total' => $this->total, | |
'count' => $this->count, | |
'links' => $this->links, | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment