Bravo3\Orm\Drivers\Filesystem\Workers\RetrieveSortedIndexWorker::execute PHP Method

execute() public method

Execute the command
public execute ( array $parameters ) : array
$parameters array
return array
    public function execute(array $parameters)
    {
        $current = $this->getJsonValue($parameters['key']);
        if ($parameters['reverse']) {
            $current = array_reverse($current);
        }
        $start = $parameters['start'];
        $stop = $parameters['stop'];
        $count = count($current);
        // Negative start/stop index
        if ($start < 0) {
            $start = $count + $start - 1;
        }
        if ($stop < 0) {
            $stop = $count + $stop;
        }
        // Slice the result if required
        if ($start || $stop) {
            // If we have a start and stop index, convert $stop to a length (it is a length if there is no start)
            if ($start && $stop) {
                $stop -= $start;
            }
            if ($start === null) {
                $start = 0;
            }
            $current = array_slice($current, $start, $stop + 1);
        }
        // We need an array of values only, ditch the score data
        $out = [];
        foreach ($current as $item) {
            $out[] = $item[1];
        }
        return $out;
    }
RetrieveSortedIndexWorker