Beispiel #1
0
 public function forOutput()
 {
     if (!$this->_definitions) {
         return [];
     }
     $this->_definitions = Objects::msort($this->_definitions, 'getDisplayName');
     return array_values(Objects::mpull($this->_definitions, 'toArray'));
 }
Beispiel #2
0
 protected function _processAlign()
 {
     if (!empty($this->_items)) {
         $counts = Objects::mpull($this->_items, 'getActionCount');
         $maxActions = max($counts);
         foreach ($this->_items as $card) {
             $card->setActionCount($maxActions);
         }
     }
 }
Beispiel #3
0
 public function testMpull()
 {
     $a = new MFilterTestHelper('1', 'a', 'q');
     $b = new MFilterTestHelper('2', 'b', 'q');
     $c = new MFilterTestHelper('3', 'c', 'q');
     $list = [$a, $b, $c];
     $expected = [1, 2, 3];
     $this->assertEquals($expected, Objects::mpull($list, 'getH'));
     $expected = ['a' => 1, 'b' => 2, 'c' => 3];
     $this->assertEquals($expected, Objects::mpull($list, 'getH', 'getI'));
     $expected = ['a' => $a, 'b' => $b, 'c' => $c];
     $this->assertEquals($expected, Objects::mpull($list, null, 'getI'));
 }
Beispiel #4
0
 /**
  * Call a method on a list of objects. Short for "method pull", this function
  * works just like @{function:ipull}, except that it operates on a list of
  * objects instead of a list of arrays. This function simplifies a common type
  * of mapping operation:
  *
  *    COUNTEREXAMPLE
  *    $names = array();
  *    foreach ($objects as $key => $object) {
  *      $names[$key] = $object->getName();
  *    }
  *
  * You can express this more concisely with mpull():
  *
  *    $names = mpull($objects, 'getName');
  *
  * mpull() takes a third argument, which allows you to do the same but for
  * the array's keys:
  *
  *    COUNTEREXAMPLE
  *    $names = array();
  *    foreach ($objects as $object) {
  *      $names[$object->getID()] = $object->getName();
  *    }
  *
  * This is the mpull version():
  *
  *    $names = mpull($objects, 'getName', 'getID');
  *
  * If you pass ##null## as the second argument, the objects will be preserved:
  *
  *    COUNTEREXAMPLE
  *    $id_map = array();
  *    foreach ($objects as $object) {
  *      $id_map[$object->getID()] = $object;
  *    }
  *
  * With mpull():
  *
  *    $id_map = mpull($objects, null, 'getID');
  *
  * See also @{function:ipull}, which works similarly but accesses array indexes
  * instead of calling methods.
  *
  * @param   $list         array          Some list of objects.
  * @param   $method       string|null   Determines which **values**
  *                        will appear in the result array. Use a string like
  *                        'getName' to store the value of calling the named
  *                        method in each value, or
  *                        ##null## to preserve the original objects.
  * @param   $keyMethod    string|null   Determines how **keys** will be
  *                        assigned in the result array. Use a string like
  *                        'getID' to use the result of calling the named method
  *                        as each object's key, or ##null## to preserve the
  *                        original keys.
  *
  * @return  array          A dictionary with keys and values derived according
  *                        to whatever you passed as $method and $key_method.
  * @group   util
  *
  * @deprecated
  */
 function mpull(array $list, $method, $keyMethod = null)
 {
     return \Packaged\Helpers\Objects::mpull($list, $method, $keyMethod);
 }
Beispiel #5
0
 /**
  * @return string[]
  */
 public function getValues()
 {
     return Objects::mpull($this->getCookies(), 'getValue', 'getName');
 }