Skip to content

Instantly share code, notes, and snippets.

@gielfeldt
Last active August 29, 2015 14:16
Show Gist options
  • Save gielfeldt/c0ca611f525878c36a65 to your computer and use it in GitHub Desktop.
Save gielfeldt/c0ca611f525878c36a65 to your computer and use it in GitHub Desktop.
Hybrid Sortable Interface
<?php
/**
* This Interface allows to hook into the global Xsort() functions.
* @ingroup SPL
* @since PHP 7.0
*/
interface Sortable
{
/**
* Sort the entries by values.
*
* @param integer $sort_flags
* SORT_REGULAR: compare items normally (don't change types)
* SORT_NUMERIC: compare items numerically
* SORT_STRING: compare items as strings
* SORT_LOCALE_STRING: compare items as strings, based on the current locale. It uses the locale, which can be changed using setlocale()
* SORT_NATURAL: compare items as strings using "natural ordering" like natsort()
* SORT_USER: compare items using user defined function
* SORT_FLAG_CASE: can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively
* SORT_FLAG_REVERSE: can be combined (bitwise OR) with any of the other options to sort in reverse
* @param callable $cmp_function
* For usort(), will be passed the user's comparison callback.
* For sort(), rsort(), natsort(), natcasesort(), will be passed a comparison defined by the engine.
*/
public function sortValues($sort_flags, callable $cmp_function);
/**
* Sort the entries by values and maintain indexes.
*
* @param integer $sort_flags
* SORT_REGULAR: compare items normally (don't change types)
* SORT_NUMERIC: compare items numerically
* SORT_STRING: compare items as strings
* SORT_LOCALE_STRING: compare items as strings, based on the current locale. It uses the locale, which can be changed using setlocale()
* SORT_NATURAL: compare items as strings using "natural ordering" like natsort()
* SORT_USER: compare items using user defined function
* SORT_FLAG_CASE: can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively
* SORT_FLAG_REVERSE: can be combined (bitwise OR) with any of the other options to sort in reverse
* @param callable $cmp_function
* For uasort(), will be passed the user's comparison callback.
* For asort(), arsort(), will be passed a comparison defined by the engine.
*/
public function sortValuesAssoc($sort_flags, callable $cmp_function);
/**
* Sort the entries by key.
*
* @param integer $sort_flags
* SORT_REGULAR: compare items normally (don't change types)
* SORT_NUMERIC: compare items numerically
* SORT_STRING: compare items as strings
* SORT_LOCALE_STRING: compare items as strings, based on the current locale. It uses the locale, which can be changed using setlocale()
* SORT_NATURAL: compare items as strings using "natural ordering" like natsort()
* SORT_USER: compare items using user defined function
* SORT_FLAG_CASE: can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively
* SORT_FLAG_REVERSE: can be combined (bitwise OR) with any of the other options to sort in reverse
* @param callable $cmp_function
* For uksort(), will be passed the user's comparison callback.
* For ksort(), krsort(), will be passed a comparison defined by the engine.
*/
public function sortKeys($sort_flags, callable $cmp_function);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment