find( $id ) ) { CatalogValidator::invalid( 'resource_id', __( 'The selected resource does not exist.', 'abece-booking' ) ); } return $id; } public static function clock( mixed $value, string $field, bool $nullable = true ): ?string { if ( null === $value && $nullable ) { return null; } if ( ! is_string( $value ) || ! preg_match( '/^(?:[01][0-9]|2[0-3]):[0-5][0-9](?::00)?$/D', $value ) ) { CatalogValidator::invalid( $field, __( 'A valid time in HH:MM format is required.', 'abece-booking' ) ); } return substr( $value, 0, 5 ) . ':00'; } public static function fixed( array $data ): array { $data['is_closed'] = CatalogValidator::boolean( $data['is_closed'], 'is_closed' ); foreach ( [ 'opens_at', 'closes_at' ] as $field ) { $data[ $field ] = self::clock( $data[ $field ], $field, $data['is_closed'] ); } if ( ! $data['is_closed'] && $data['opens_at'] >= $data['closes_at'] ) { CatalogValidator::invalid( 'closes_at', __( 'Closing time must be after opening time on the same day.', 'abece-booking' ) ); } if ( $data['is_closed'] ) { $data['opens_at'] = null; $data['closes_at'] = null; } return $data; } }