> */ private array $items; /** * 1-based page number echoed back from the originating query. */ private int $page; /** * Records per page echoed back from the originating query. */ private int $perPage; /** * Total matching rows across every page (after filtering, * before pagination). */ private int $total; /** * Total page count derived from `$total` / `$perPage`. */ private int $pageCount; /** * Construct the result with explicit values for every axis. * * @param list> $items Wire-projected row slice. * @param int $page 1-based page number (>= 0). * @param int $perPage Records per page (>= 0). * @param int $total Total matching rows (>= 0). * @param int $pageCount Total page count (>= 0). * * @throws InvalidArgumentException When any int axis is negative. */ public function __construct( array $items, int $page, int $perPage, int $total, int $pageCount ) { if ( $page < 0 ) { $message = sprintf( 'ListSyncJobsResult: page must be >= 0, got %d.', $page ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Developer-facing message, never rendered to HTML. throw new InvalidArgumentException( $message ); } if ( $perPage < 0 ) { $message = sprintf( 'ListSyncJobsResult: perPage must be >= 0, got %d.', $perPage ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Developer-facing message, never rendered to HTML. throw new InvalidArgumentException( $message ); } if ( $total < 0 ) { $message = sprintf( 'ListSyncJobsResult: total must be >= 0, got %d.', $total ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Developer-facing message, never rendered to HTML. throw new InvalidArgumentException( $message ); } if ( $pageCount < 0 ) { $message = sprintf( 'ListSyncJobsResult: pageCount must be >= 0, got %d.', $pageCount ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Developer-facing message, never rendered to HTML. throw new InvalidArgumentException( $message ); } $this->items = array_values( $items ); $this->page = $page; $this->perPage = $perPage; $this->total = $total; $this->pageCount = $pageCount; } /** * Wire-projected row slice in newest-first order. * * @return list> */ public function items(): array { return $this->items; } /** * 1-based page number echoed back from the originating query. */ public function page(): int { return $this->page; } /** * Records per page echoed back from the originating query. */ public function perPage(): int { return $this->perPage; } /** * Total matching rows across every page. */ public function total(): int { return $this->total; } /** * Total page count derived from `$total` / `$perPage`. */ public function pageCount(): int { return $this->pageCount; } /** * Render the §11.3 success envelope `data` shape: * * `array( * 'items' => list>, * 'page' => int, * 'per_page' => int, * 'total' => int, * 'page_count' => int, * )` * * @return array{ * items: list>, * page: int, * per_page: int, * total: int, * page_count: int, * } */ public function toArray(): array { return array( 'items' => $this->items, 'page' => $this->page, 'per_page' => $this->perPage, 'total' => $this->total, 'page_count' => $this->pageCount, ); } }