コード例 #1
0
ファイル: ColumnAliasHandler.php プロジェクト: letsdrink/ouzo
 public static function createSelectColumnsWithAliases($prefix, $columns, $alias)
 {
     return FluentArray::from($columns)->toMap(function ($field) use($prefix) {
         return "{$prefix}{$field}";
     }, function ($field) use($alias) {
         return "{$alias}.{$field}";
     })->toArray();
 }
コード例 #2
0
ファイル: FieldTransformer.php プロジェクト: letsdrink/ouzo
 public function transform(&$results)
 {
     if ($this->field) {
         $fields = FluentArray::from($results)->map(Functions::extractExpression($this->field))->flatten()->filterNotBlank()->toArray();
         $this->transformer->transform($fields);
     } else {
         $this->transformer->transform($results);
     }
 }
コード例 #3
0
ファイル: DialectUtil.php プロジェクト: letsdrink/ouzo
 public static function buildUsingQuery($usingClauses, $glue, $table, $alias)
 {
     $elements = FluentArray::from($usingClauses)->map('\\Ouzo\\Db\\Dialect\\DialectUtil::buildUsingQueryPart')->toArray();
     if ($usingClauses && $table) {
         $tableElement = $table . ($alias ? " AS {$alias}" : "");
         $elements = array_merge(array($tableElement), $elements);
     }
     return implode($glue, $elements);
 }
コード例 #4
0
 public function convert($results)
 {
     $aliasToOffset = $this->_createAliasToOffsetMap();
     $joinsToStore = FluentArray::from($this->joinedModels)->filter(Functions::extract()->storeField())->uniqueBy(Functions::extract()->destinationField())->toArray();
     $models = array();
     foreach ($results as $row) {
         $models[] = $this->convertRowToModel($row, $aliasToOffset, $joinsToStore);
     }
     return $this->_fetchRelations($models, $joinsToStore);
 }
コード例 #5
0
ファイル: RelationFetcher.php プロジェクト: letsdrink/ouzo
 public function transform(&$results)
 {
     $localKeyName = $this->_relation->getLocalKey();
     $localKeys = FluentArray::from($results)->map(Functions::extractField($localKeyName))->filterNotBlank()->unique()->toArray();
     $relationObjectsById = $localKeys ? $this->_loadRelationObjectsIndexedById($localKeys) : array();
     foreach ($results as $result) {
         $values = $this->_findRelationObject($relationObjectsById, $result->{$localKeyName});
         $destinationField = $this->_relation->getName();
         $result->{$destinationField} = $this->_relation->extractValue($values);
     }
 }
コード例 #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
ファイル: RouteRule.php プロジェクト: letsdrink/ouzo
 public function setParameters($uri)
 {
     $ruleUri = explode('/', $this->getUri());
     $requestUri = explode('/', $uri);
     $filterParameters = FluentArray::from($ruleUri)->filter(function ($parameter) {
         return preg_match('#:\\w+#', $parameter);
     })->map(function ($parameter) {
         return str_replace(':', '', $parameter);
     })->toArray();
     $filterValues = array_intersect_key($requestUri, $filterParameters);
     $this->parameters = Arrays::combine($filterParameters, $filterValues);
 }
コード例 #8
0
ファイル: FluentArrayTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldSortElements()
 {
     //given
     $array = array(4, 1, 3, 2);
     //when
     $result = FluentArray::from($array)->sort(Comparator::natural())->toArray();
     //then
     $this->assertEquals(array(1, 2, 3, 4), $result);
 }