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

execute() public method

Execute the command
public execute ( array $parameters ) : void
$parameters array
return void
    public function execute(array $parameters)
    {
        $key = $parameters['key'];
        $value = $parameters['value'];
        $score = $parameters['score'];
        $content = $this->getJsonValue($key);
        // Search existing content
        foreach ($content as $index => $item_data) {
            list(, $item) = $item_data;
            if ($item == $value) {
                // Overwrite existing value
                $content[$index] = [$score, $item];
                $this->sortAndWrite($content, $key);
                return;
            }
        }
        // Append new value
        $content[] = [$score, $value];
        $this->sortAndWrite($content, $key);
    }