extract() публичный статический Метод

public static extract ( null $type = null ) : Ouzo\Utilities\NonCallableExtractor
$type null
Результат Ouzo\Utilities\NonCallableExtractor
Пример #1
0
 private function _fetchRelations($results, $joinsToStore)
 {
     $joinedRelations = Arrays::map($joinsToStore, Functions::extract()->destinationField());
     foreach ($this->relationsToFetch as $relationToFetch) {
         if (!in_array($relationToFetch->destinationField, $joinedRelations)) {
             $relationFetcher = new RelationFetcher($relationToFetch->relation);
             $fieldTransformer = new FieldTransformer($relationToFetch->field, $relationFetcher);
             $fieldTransformer->transform($results);
         }
     }
     return $results;
 }
 private function _parseArgs($args, $parameters)
 {
     $args = Arrays::getValue($args, 0, new stdClass());
     $newArgs = array();
     $parameterNames = Arrays::map($parameters, Functions::extract()->getName());
     foreach ($parameterNames as $name) {
         if (isset($args->{$name})) {
             $newArgs[] = $args->{$name};
         }
     }
     return $newArgs;
 }
Пример #3
0
 public function getClosedByRoundForCricket()
 {
     $hits = Hit::join('game_user->user')->where(['game_user_id' => $this->id])->order('hits.id asc')->fetchAll();
     $byRound = Arrays::groupBy($hits, Functions::extract()->round);
     $closedInRound = [];
     $closed = [15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 25 => 0];
     foreach ($byRound as $round => $hits) {
         $closedInCurrentRound = 0;
         foreach ($hits as $hit) {
             if (isset($closed[$hit->field])) {
                 $closedField = min($hit->multiplier, 3 - $closed[$hit->field]);
                 $closedInCurrentRound += $closedField;
                 $closed[$hit->field] += $closedField;
             }
         }
         $closedInRound[$round] = $closedInCurrentRound;
     }
     return $closedInRound;
 }
 public static function prepare(array $whereClauses = array())
 {
     $where = Joiner::on(' AND ')->mapValues(Functions::extract()->getWhere())->join($whereClauses);
     return new self($where);
 }
 private function prepare()
 {
     $moduleFields = (array) $this->result->module_fields;
     $this->fields = array_values(Arrays::map($moduleFields, Functions::extract()->name));
 }
Пример #6
0
 /**
  * @test
  */
 public function shouldFetchRelationThroughOneToManyRelation()
 {
     //given
     $phones = Category::create(array('name' => 'phones'));
     $sony = Manufacturer::create(array('name' => 'sony'));
     Product::create(array('name' => 'best ever sony', 'id_category' => $phones->id, 'id_manufacturer' => $sony->id));
     $tablets = Category::create(array('name' => 'tablets'));
     $samsung = Manufacturer::create(array('name' => 'samsung'));
     Product::create(array('name' => 'best ever samsung', 'id_category' => $tablets->id, 'id_manufacturer' => $samsung->id));
     //when
     $categories = Category::where()->with('products->manufacturer')->fetchAll();
     Stats::reset();
     //then
     Assert::thatArray(FluentArray::from($categories)->map(Functions::extract()->products)->flatten()->map(Functions::extract()->manufacturer->name)->toArray())->containsOnly('sony', 'samsung');
     $this->assertEquals(0, Stats::getNumberOfQueries());
     //no lazily loaded relations
 }
Пример #7
0
 public function delete()
 {
     $attributes = Arrays::map($this->whereClauses, Functions::extract()->getParams());
     $queryInsert = new QueryInsert(Arrays::firstOrNull($attributes));
     $id = $queryInsert->into($this->module->getModuleName());
     return !is_null($id);
 }
Пример #8
0
 /**
  * @test
  */
 public function shouldExtractArrayValue()
 {
     //given
     $object = array('key' => 'value');
     //$function = Functions::extract()['key']; only i php 5.4
     $function = Functions::extract()->offsetGet('key');
     //when
     $result = Functions::call($function, $object);
     //then
     Assert::thatString($result)->isEqualTo('value');
 }
Пример #9
0
 /**
  * @test
  */
 public function shouldExtractRecursivelyArrayColumn()
 {
     //given
     $array = array(array('id' => 123, 'name' => 'value1', 'test' => array('number' => 90)), array('id' => 123, 'name' => 'value1', 'test' => array('number' => 100)));
     //when
     $numbers = Arrays::map($array, Functions::extract()->test->number);
     //then
     Assert::thatArray($numbers)->hasSize(2)->containsOnly(90, 100);
 }
Пример #10
0
 /**
  * @test
  */
 public function shouldReturnObjectsGroupedByFunctionResults()
 {
     //given
     $array = array($product1 = new Product(array('name' => 'bob')), $product2 = new Product(array('name' => 'john')), $product3 = new Product(array('name' => 'bob')));
     //when
     $groupedByName = FluentArray::from($array)->groupBy(Functions::extract()->name)->toArray();
     //then
     $this->assertSame(array('bob' => array($product1, $product3), 'john' => array($product2)), $groupedByName);
 }