Переделка для composer autoload

This commit is contained in:
origami11 2017-02-09 14:57:40 +03:00
parent ad69746347
commit b5641db607
100 changed files with 14 additions and 325 deletions

58
src/sort.php Normal file
View file

@ -0,0 +1,58 @@
<?php
class SortRecord
{
function __construct($key, $mode, $order)
{
$this->key = $key;
$this->order = ((boolean)($order) === false) ? 1 : -1;
$this->mode = $mode;
}
function compare($a, $b)
{
if($a[$this->key] == $b[$this->key]) {
return 0;
}
return ($a[$this->key] > $b[$this->key]) ? $this->order : -$this->order;
}
function compareKeys($a, $b)
{
if($a->{$this->key} == $b->{$this->key}) {
return 0;
}
return ($a->{$this->key} > $b->{$this->key}) ? $this->order : -$this->order;
}
function sort(&$list)
{
return usort($list, array($this, 'compare'));
}
function sortKeys(&$list)
{
return usort($list, array($this, 'compareKeys'));
}
function group(&$list, $key, $types)
{
$groups = array();
foreach ($types as $name) {
$groups[$name] = array();
}
$groups['_any_'] = array();
foreach ($list as $item) {
if (isset($groups[$item[$key]])) {
$groups[$item[$key]][] = $item;
} else {
$groups['_any_'][] = $item;
}
}
$result = array();
foreach ($groups as $value) {
$result = array_merge($result, $value);
}
$list = $result;
}
}