2017 © Pedro Peláez
 

library method-sort

Misc framework/library agnostic utility classes and objects

image

honeycomb/method-sort

Misc framework/library agnostic utility classes and objects

  • Thursday, March 8, 2018
  • by btam06
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Honeycomb

Honeycomb is a collection of useful utility objects that are framework/library agnostic. Each class aims to do one thing and do it well., (*1)

MethodSort

The MethodSort class is a stateful object which implements __invoke, such that an instance of the object can be passed as a preconfigured comparison function for standard sorting. Method sort enables ordering objects via the results of called methods., (*2)

For example. Let's say you have a Person:, (*3)

class Person {
    public function __construct($firstname, $lastname) {
        $this->firstname = $firstname;
        $this->lastname  = $lastname;
    }

    public function getFirstName()
    {
        return $this->firstname;
    }

    public function getLastName()
    {
        return $this->lastname;
    }
}

Now let's say you have an array of people:, (*4)

$objects     = [
    'ms' => new Person('Matthew', 'Sahagian'),
    'mj' => new Person('Matthew', 'Jones'),
    'bt' => new Person('Brian', 'Tam')
];

You can sort them, by first name, then by last name using MethodSort:, (*5)

$method_sort = new Honeycomb\MethodSort();

$method_sort->setOrder([
    'getFirstName' => 'asc',
    'getLastName'  => 'asc'
]);

uasort($objects, $method_sort);

Objects now contains:, (*6)

array (
  'bt' =>
  Person::__set_state(array(
     'firstname' => 'Brian',
     'lastname' => 'Tam',
  )),
  'mj' =>
  Person::__set_state(array(
     'firstname' => 'Matthew',
     'lastname' => 'Jones',
  )),
  'ms' =>
  Person::__set_state(array(
     'firstname' => 'Matthew',
     'lastname' => 'Sahagian',
  )),
)

The Versions

08/03 2018

dev-master

9999999-dev

Misc framework/library agnostic utility classes and objects

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Brian Tam
by Matthew Sahagian

08/03 2018

1.0.0

1.0.0.0

Misc framework/library agnostic utility classes and objects

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Brian Tam
by Matthew Sahagian