2015-02-24 17:36 GMT+01:00 Benjamin Eberlei <kont...@beberlei.de>:

> Hi,
>
> On Tue, Feb 24, 2015 at 5:17 PM, Thomas Gielfeldt <tho...@gielfeldt.dk>
> wrote:
>
>> Hi internals.
>>
>> I've made PR proposing a feature request: A new interface Sortable.
>>
>> https://github.com/php/php-src/pull/1116
>>
>> If possible, I would like to create and RFC describing this in more
>> detail,
>> and perhaps get a voting on.
>>
>
> so you need to implement all methods? This can probably be considered a
> violation of the Interface Segregation Principle. But adding an interface
> for each method seems a bit much as well.
>
>>
>>
I have some more proposals for how to implement this interface. Should we
create an RFC for purposes of discussion, or do you usually do this in the
mailing lists?

1 interface with 2 methods, controlled by flags.

/** @ingroup SPL
 * @brief This Interface allows to hook into the global sort() functions.
 * @since PHP 5.1
 */
interface Sortable
{
  /**
   * Sort values or keys.
   * @param int $flags
   *   SORT_REGULAR
   *   SORT_NUMERIC
   *   SORT_STRING
   *   SORT_LOCALE_STRING
   *   SORT_NATURAL
   *   -- bitwise flags
   *   SORT_SORT_FLAG_CASE - case insensitive sorting.
   *   SORT_REVERSE - sort in reverse.
   *   SORT_KEYS - sort keys.
   *   SORT_INDEX - maintain indexes.
   * @return bool
   *   TRUE on success.
   */
  function sort($flags);

  /**
   * Sort values or keys.
   * @param callback $cmp_function
   *   Compare callback
   * @return bool
   *   TRUE on success.
   */
  function usort($cmp_function);
}


-----------------------------


4 interfaces with 1 method, controlled by flags.

/** @ingroup SPL
 * @brief This Interface allows to hook into the global sort() functions.
 * @since PHP 5.1
 */
interface Sortable
{
  /**
   * Sort values.
   * @param int $flags
   *   SORT_REGULAR
   *   SORT_NUMERIC
   *   SORT_STRING
   *   SORT_LOCALE_STRING
   *   SORT_NATURAL
   *   -- bitwise flags
   *   SORT_SORT_FLAG_CASE - case insensitive sorting.
   *   SORT_REVERSE - sort in reverse.
   * @return bool
   *   TRUE on success.
   */
  function sort($flags);
}

/** @ingroup SPL
 * @brief This Interface allows to hook into the global aXsort() functions.
 * @since PHP 5.1
 */
interface SortableIndex
{
  /**
   * Sort values and maintain index association.
   * @param int $flags
   *   SORT_REGULAR
   *   SORT_NUMERIC
   *   SORT_STRING
   *   SORT_LOCALE_STRING
   *   SORT_NATURAL
   *   -- bitwise flags
   *   SORT_SORT_FLAG_CASE - case insensitive sorting.
   *   SORT_REVERSE - sort in reverse.
   * @return bool
   *   TRUE on success.
   */
  function asort($flags);
}

/** @ingroup SPL
 * @brief This Interface allows to hook into the global kXsort() functions.
 * @since PHP 5.1
 */
interface SortableKeys
{
  /**
   * Sort keys.
   * @param int $flags
   *   SORT_REGULAR
   *   SORT_NUMERIC
   *   SORT_STRING
   *   SORT_LOCALE_STRING
   *   SORT_NATURAL
   *   -- bitwise flags
   *   SORT_SORT_FLAG_CASE - case insensitive sorting.
   *   SORT_REVERSE - sort in reverse.
   * @return bool
   *   TRUE on success.
   */
  function ksort($flags);
}

/** @ingroup SPL
 * @brief This Interface allows to hook into the global uXsort() functions.
 * @since PHP 5.1
 */
interface SortableUser
{
  /**
   * Sort values or keys.
   * @param callback $cmp_function
   *   Compare callback
   * @return bool
   *   TRUE on success.
   */
  function usort($cmp_function);
}


The natsort() and natcasesort() can already be covered by sort() through
flags, so I think we should leave them out.




> Thanks
>>
>> Br,
>>
>> Thomas Gielfeldt
>>
>
>

Reply via email to