public static function extractExpression($selector, $accessPrivate = false) { if (!is_string($selector)) { return $selector; } elseif (strpos($selector, '()') !== false || strpos($selector, '->') !== false) { return Functions::extractFieldRecursively($selector, $accessPrivate); } else { return Functions::extractField($selector, $accessPrivate); } }
/** * @test */ public function shouldConvertToMap() { //given $obj[0] = new stdClass(); $obj[0]->field1 = 'key1'; $obj[0]->field2 = 'value1'; $obj[1] = new stdClass(); $obj[1]->field1 = 'key2'; $obj[1]->field2 = 'value2'; //when $toMap = FluentArray::from($obj)->toMap(Functions::extractField('field1'), Functions::extractField('field2'))->toArray(); //then $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $toMap); }
private function _loadRelationObjectsIndexedById($localKeys) { $relationObject = $this->_relation->getRelationModelObject(); $relationObjects = $relationObject::where(array($this->_relation->getForeignKey() => $localKeys))->where($this->_relation->getCondition())->order($this->_relation->getOrder())->fetchAll(); return Arrays::groupBy($relationObjects, Functions::extractField($this->_relation->getForeignKey())); }
public function extractCompaniesNames($companies) { return Arrays::map($companies, Functions::extractField('name')); }
/** * @test */ public function shouldGroupByAndSort() { //given $product1 = new Product(array('name' => 'a', 'description' => '1', 'id_category' => '1')); $product2 = new Product(array('name' => 'b', 'description' => '2', 'id_category' => '2')); $product3 = new Product(array('name' => 'c', 'description' => '2', 'id_category' => '1')); $array = array($product1, $product2, $product3); //when $grouped = Arrays::groupBy($array, Functions::extractField('description'), 'id_category'); //then $this->assertEquals(array('1' => array($product1), '2' => array($product3, $product2)), $grouped); }
public function getErrors() { return Arrays::map($this->_errors, Functions::extractField('message')); }