public function forOutput() { if (!$this->_definitions) { return []; } $this->_definitions = Objects::msort($this->_definitions, 'getDisplayName'); return array_values(Objects::mpull($this->_definitions, 'toArray')); }
public function testMsort() { $a = new MFilterTestHelper('1', 'a', 'q'); $b = new MFilterTestHelper('2', 'b', 'q'); $c = new MFilterTestHelper('3', 'c', 'q'); $list = ["b" => $b, "a" => $a, "c" => $c]; $expected = ["a" => $a, "b" => $b, "c" => $c]; $this->assertEquals($expected, Objects::msort($list, 'getI')); }
/** * Sort a list of objects by the return value of some method. In PHP, this is * often vastly more efficient than ##usort()## and similar. * * // Sort a list of Duck objects by name. * $sorted = msort($ducks, 'getName'); * * It is usually significantly more efficient to define an ordering method * on objects and call ##msort()## than to write a comparator. It is often more * convenient, as well. * * NOTE: This method does not take the list by reference; it returns a new list. * * @param $list array List of objects to sort by some property. * @param $method string Name of a method to call on each object; the return * values will be used to sort the list. * * @return array Objects ordered by the return values of the method calls. * @group util * * @deprecated */ function msort(array $list, $method) { return \Packaged\Helpers\Objects::msort($list, $method); }