entryService = $entryService; } /** * @param WP_REST_Request $data * * @return WP_REST_Response * @throws ForbiddenException * @throws InvalidArgumentException * @throws ValidationException */ public function handle(WP_REST_Request $data): WP_REST_Response { // Verify the nonce Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); // Sanitize the filtering data $params = Sanitizer::sanitizeSearchParams($data->get_query_params()); // Call the searchEntries method $entriesArr = $this->entryService->searchEntries($params); // Map the data to Entry entities $entries = array_map(function ($entryData) { $entryEntity = EntryFactory::create($entryData); return $entryEntity->toArray(); }, $entriesArr['data']); $filterCount = $this->entryService->getFilterCount($params); $entryFields = $this->entryService->getEntryFields($entriesArr['data']); // Return the response with data and meta return new WP_REST_Response([ 'message' => BackendStrings::getCommonStrings()['ok'], 'data' => [ 'data' => $entries, 'meta' => $entriesArr['meta'] ?? [], 'filterCount' => $filterCount, 'entryFields' => $entryFields, ], ], 200); } }