shotstack / shotstack-sdk-php

PHP SDK for Shotstack, the cloud video editing API.
https://shotstack.io/product/sdk/php/
11 stars 5 forks source link

[Suggestion] Allow manual setting on Track layer order #5

Open ghost opened 4 years ago

ghost commented 4 years ago

Just a suggestion, but it would be great to have the ability to manually set each Tracks order, rather than only having the option of array index.

For example, I've found I need to add layers out of order, so I've had to create a middleware that allows me to re-order the Tracks before committing them to the SDK.

If Track had an order attribute and setter available, which fell-back/defaulted to the upstream Timeline array priority that would be incredible.

eg:

<?php
namespace Shotstack\Client\Model;
class Track implements ModelInterface, ArrayAccess
{
  //...
   public function setOrder(int $order)
    {
        $this->container['order'] = $order;

        return $this;
    }

    public function getOrder()
    {
        return $this->container['order'] ?? null;
    }
}
<?php
namespace Shotstack\Client\Model;
class Timeline implements ModelInterface, ArrayAccess
{
  //...
  public function getTracks()
    {
       $originalTracks = $this->container['tracks'];
        $orderedTracks = [];
        $tracks = [];
        foreach($originalTracks as $track) {
           if($track->getOrder()) {
               $orderedTracks[] = $track;
           } else { 
              $tracks[] = $track;
           }
        }
        // I'm using a third-party library here to pull all the ...
        array_unshift($orderedTracks, $tracks);

        return $tracks;
    }
}
jeffski commented 4 years ago

Thank you for the suggestion. Will look at how we can integrate this. Right now our SDK's are generated automatically using this project https://github.com/shotstack/oas-api-definition which makes customisation a bit tricky, although we do already have to manually make a few tweaks each time anyway.