HEX
Server: Apache
System: Linux cpanelx.inxs.ro 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: crowdandsafety (1041)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/cwd/wp-content/plugins/cornerstone/includes/classes/Util/StableSorter.php
<?php

namespace Themeco\Cornerstone\Util;

class StableSorter {
  protected $userCmp;
  protected $i;
  
  protected function setCmp( $cmp ) {
    $this->userCmp = $cmp;
  }

  protected function cmp($a, $b) {
    $user = call_user_func( $this->userCmp, $a[1], $b[1]);
    return $user ?: ($a[0] - $b[0]);
  }

  protected function index_array( $el ) {
    return array( $this->i++, $el );
  }

  public function sort( $array ) {
    $this->i = 0;
    $indexed = array_map( array( $this, 'index_array' ), $array );
    usort($indexed, array( $this, 'cmp'));
    $indexed = array_column($indexed, 1);
    return $indexed;
  }
  
  public static function make( $cmp ) {
    $sorter = new self();
    $sorter->setCmp( $cmp );
    return $sorter;
  }
  
}