'GET','permission_callback'=>[$this,'permission'],'callback'=>fn()=>$this->respond(fn()=>$this->service->listing(get_current_user_id()))], ['methods'=>'POST','permission_callback'=>[$this,'permission'],'callback'=>function($r){return $this->respond(function()use($r){if(!is_object(json_decode($r->get_body())))throw new CatalogException('abece_booking_invalid_json',__('A JSON object is required.','abece-booking'),400);return $this->service->submit($r->get_json_params(),get_current_user_id());});}], ]); } public function permission(\WP_REST_Request $r):bool|\WP_Error { if(!is_user_logged_in())return new \WP_Error('abece_booking_login_required',__('Log in to manage your personal data.','abece-booking'),['status'=>401]); if($r->get_method()!=='GET'&&!wp_verify_nonce($r->get_header('X-WP-Nonce'),'wp_rest'))return new \WP_Error('rest_cookie_invalid_nonce',__('The security check failed. Reload the page and try again.','abece-booking'),['status'=>403]);return true; } private function respond(callable $work):\WP_REST_Response|\WP_Error { try{$r=new \WP_REST_Response($work());$r->header('Cache-Control','private, no-store');$r->header('Vary','Cookie');return $r;} catch(CatalogException $e){return new \WP_Error($e->errorCode,$e->getMessage(),['status'=>$e->status,'field'=>$e->field]);} catch(\Throwable){return new \WP_Error('abece_booking_privacy_processing',__('Privacy processing could not be completed. Restart the request or contact the operator.','abece-booking'),['status'=>503]);} } }