meilisearch-php icon indicating copy to clipboard operation
meilisearch-php copied to clipboard

Replace array return types from api to object

Open norkunas opened this issue 1 year ago • 8 comments

Description Currently all enqueued tasks are returned as an array without defined structure, so basically we cannot be sure that is safe to access any data from it. As I've seen structure can differ per task status, but I could be mistaken. This idea came up to my mind after I've seen https://github.com/meilisearch/meilisearch-js/blob/main/src/enqueued-task.ts

Basic example

class EnqueuedTask implements \ArrayAccess
{
  private int $taskUid;
  private string indexUid;
  private string $status; //  'succeeded'|'processing'|'failed'|'enqueued'|'canceled'; // this could be class constants and later migrated to enums after bumping up php requirement to 8+
  private string $type; // ...
  private DateTimeImmutable $enqueuedAt;
}

This could act as a base, and if response data is really different per task status, then we could extend this object into many ones with more additional information. another approach of course would be just add all data to EnqueuedTask and for consumers to check status before accessing it

Other This is related to #573

To break things less the returned lets say EnqueuedTask object could implement the ArrayAccess interface so array access would still work, it would just break things if someone has extended any of Endpoint classes.

norkunas avatar Dec 09 '24 13:12 norkunas

We could make this change and also move on to the minimum supported PHP version to 8.0, WDYT?

brunoocasali avatar Dec 11 '24 12:12 brunoocasali

I'd even say 8.1 or 8.2 :)

norkunas avatar Dec 11 '24 12:12 norkunas

Would dropping support for php 7 require new release (2.0)? I would imagine so.

tacman avatar Mar 06 '25 15:03 tacman

@tacman not necessarily. if app is on php 7 and meilisearch starts to support only ^php8, then the composer won't update the package and that's all, unless ignore-platform-reqs flag would be used

norkunas avatar Mar 07 '25 04:03 norkunas

yes, though generally a bump like changing the minimum PHP version is also tied to a version bump.

Additionally, we could rename some of the methods to indicate which ones actually make an API call. Or maybe once I'm more familiar with the library, it'll be obvious, and certainly getting an enqueued task will be a huge indicator.

tacman avatar Mar 07 '25 10:03 tacman

@tacman version bump can be minor - as I'd say it's a feature, not necessarily a breaking change

norkunas avatar Mar 07 '25 10:03 norkunas

Is there a branch that has the EnqueuedTask class written? I think the ArrayAccess idea is a pretty cool way to maintain b/c.

tacman avatar Mar 07 '25 11:03 tacman

https://github.com/meilisearch/meilisearch-php/compare/main...norkunas:meilisearch-php:enqueued-task i had this locally for at least 3-4 months, but commited now, if you want to complete go ahead

norkunas avatar Mar 07 '25 11:03 norkunas