repository->list( $page, $per_page, $filters ); } public function get( int $id ): array { \ABeCe\Booking\Edition\ServicePolicy::check($this); return $this->repository->find( $id ) ?? throw new CatalogException( 'abece_booking_not_found', __( 'The item was not found.', 'abece-booking' ), 404 ); } public function save( array $input, ?int $id = null ): array { \ABeCe\Booking\Edition\ServicePolicy::check($this); $unknown = array_diff( array_keys( $input ), $this->fields() ); if ( $unknown ) { throw new CatalogException( 'abece_booking_unknown_field', __( 'The request contains an unsupported field.', 'abece-booking' ), 400, (string) reset( $unknown ) ); } $current = null === $id ? [] : array_intersect_key( $this->get( $id ), array_flip( $this->fields() ) ); $data = $this->validate( $input, $current ); if ( isset( $data['slug'] ) ) { $existing = $this->repository->findBySlug( $data['slug'] ); if ( $existing && $existing['id'] !== $id ) { throw new CatalogException( 'abece_booking_duplicate_slug', __( 'This slug is already in use.', 'abece-booking' ), 409, 'slug' ); } } return $this->persist( $data, $id ); } protected function persist( array $data, ?int $id ): array { return $this->repository->save( $data, $id ); } public function delete( int $id ): void { \ABeCe\Booking\Edition\ServicePolicy::check($this); $this->get( $id ); $this->repository->delete( $id ); } }