当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::merge方法代码示例

本文整理汇总了PHP中Collection::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::merge方法的具体用法?PHP Collection::merge怎么用?PHP Collection::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Collection的用法示例。


在下文中一共展示了Collection::merge方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: newMerged

 public static function newMerged(array $decks)
 {
     $merged = new Collection();
     foreach ($decks as $deck) {
         $merged->merge($deck);
     }
     return new static($merged);
 }
开发者ID:sixteenstudio,项目名称:poker,代码行数:8,代码来源:Deck.php

示例2: testMerge

 public function testMerge()
 {
     $collection1 = new Collection(['a', 'b']);
     $collection2 = new Collection(['a', 'c']);
     $collection3 = new Collection(['d', 'e']);
     $result = $collection1->merge($collection2, $collection3);
     $this->assertNotSame($collection1, $result);
     $this->assertInstanceOf(get_class($collection1), $result);
     $this->assertSame(['a', 'b', 'a', 'c', 'd', 'e'], (array) $result);
 }
开发者ID:Raphhh,项目名称:trex-collection,代码行数:10,代码来源:CollectionComparatorTraitTest.php

示例3: smarty_function_origin_picker

function smarty_function_origin_picker($params, &$smarty)
{
    $gf = new GroupFilter(new PFC_And(new PFC_Not(new GFC_Namespace(Group::NS_USER)), new GFC_User(S::user(), Rights::admin())), new GFO_Score());
    $gs = $gf->get();
    if ($params['not_only_admin']) {
        $gfo = new GroupFilter(new PFC_And(new GFC_Namespace(array(Group::NS_BINET, Group::NS_FREE)), new GFC_User(S::user(), Rights::restricted())), new GFO_Score());
        $gso = $gfo->get()->diff($gs);
        $temp = new Collection();
        $temp->merge($gs)->merge($gso);
        $temp->select(GroupSelect::base());
        $smarty->assign('not_admin', $gso);
    } else {
        $gs = $gf->get()->select(GroupSelect::base());
    }
    $smarty->assign($params['out'], $gs);
}
开发者ID:netixx,项目名称:frankiz,代码行数:16,代码来源:function.origin_picker.php

示例4: query

 /**
  * @param string $table
  * @param mixed $hash
  * @param Context\Query $context
  * @return \Riverline\DynamoDB\Collection
  */
 public function query($table, $hash, Context\Query $context = null)
 {
     $collection = new Collection();
     do {
         try {
             $items = $this->connection->query($table, $hash, $context);
             $collection->merge($items);
             if ($items->more()) {
                 $context = $items->getNextContext();
             } else {
                 // End
                 break;
             }
         } catch (\Riverline\DynamoDB\Exception\ProvisionedThroughputExceededException $e) {
             // Continue
         }
     } while (true);
     return $collection;
 }
开发者ID:16hands,项目名称:riverline-dynamodb,代码行数:25,代码来源:Repeater.php

示例5: smarty_function_target_picker

function smarty_function_target_picker($params, &$smarty)
{
    // Get user groups
    $everybody_groups = S::user()->castes(Rights::everybody())->groups();
    // Get Frankiz special groups
    $fkz = new Collection('Group');
    $fkz->add(array('everybody', 'public'));
    $fkz->select(new GroupSelect(array('description')));
    // BDE, study and promo groups
    $study_groups = $everybody_groups->filter('ns', Group::NS_BDE);
    $study_groups->merge($everybody_groups->filter('ns', Group::NS_PROMO));
    $study_groups->merge($everybody_groups->filter('ns', Group::NS_STUDY));
    // Get all groups user is admin, without the user one
    $gs = S::user()->castes(Rights::admin())->groups();
    $gs->diff($fkz);
    $gs->filter(function ($g) {
        return $g->ns() != Group::NS_USER;
    });
    if ($params['even_only_friend']) {
        $gfo = new GroupFilter(new PFC_And(new GFC_Namespace(array(Group::NS_BINET, Group::NS_FREE)), new GFC_User(S::user(), Rights::everybody())), new GFO_Score());
        $gso = $gfo->get()->diff($gs)->diff($fkz);
        $temp = new Collection();
        $temp->merge($gs)->merge($gso);
        $temp->select(GroupSelect::base());
        $smarty->assign('only_friend', $gso);
        $temp = new Collection();
        $temp->merge($gs)->merge($fkz)->merge($gso);
        $temp->select(GroupSelect::base());
    } else {
        $temp = new Collection();
        $temp->merge($gs)->merge($fkz);
        $temp->select(GroupSelect::base());
    }
    $smarty->assign($params['user_groups'], $gs);
    $smarty->assign($params['fkz_groups'], $fkz);
    $smarty->assign($params['study_groups'], $study_groups);
    $smarty->assign($params['own_group'], S::user()->group());
}
开发者ID:netixx,项目名称:frankiz,代码行数:38,代码来源:function.target_picker.php

示例6: test3_Appending

 public function test3_Appending()
 {
     $collection = new Collection(new Yaml());
     $collection_of_values = new Collection(new Yaml());
     # appending
     static::$collection->append('part1.item2', ['name' => 'Janice']);
     $this->assertEquals('Janice', static::$collection->get('part1.item2.name'));
     static::$collection->forget('part1');
     static::$collection->append('part1', ['item2' => ['name' => 'Janice']]);
     static::$collection->with('with', 'with test');
     $this->assertEquals('with test', static::$collection->get('with'));
     $this->assertTrue(static::$collection->count() === 2);
     static::$collection->forget('with');
     $this->assertTrue(static::$collection->count() === 1);
     # setup
     $test_array = ['merge_with' => ['merge' => 'this']];
     $collection_of_values->with($test_array);
     # test with an array
     $collection->merge($test_array);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     $collection->forget('merge_with');
     # test with a collection as a value object
     $collection->merge($collection_of_values);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     $collection->forget('merge_with');
     # test with value object
     $value_object = new \stdClass();
     $value_object->merge_with = $test_array['merge_with'];
     $collection->merge($value_object);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     # test with flat array
     $collection->merge(Util::array_from_str('merge with'));
     $this->assertEquals($collection->get('merge'), NULL);
     $this->assertEquals($collection->get('with'), NULL);
     $this->setExpectedException('InvalidArgumentException', "Cannot append an already existing key: 'part1'");
     static::$collection->append('part1', ['item2' => ['name' => 'Mary']]);
 }
开发者ID:anctemarry27,项目名称:cogs,代码行数:37,代码来源:CollectionTest.php

示例7: GroupFilter

 function handler_groups($page)
 {
     global $globals;
     $except = new PFC_True();
     $max = $globals->groups->limit;
     // Re-fetch user's groups
     S::user()->select(UserSelect::castes());
     // Fetch samples of other groups
     $binet = new GroupFilter(new PFC_And(new GFC_Namespace(Group::NS_BINET), $except), new GFO_Score(true));
     $binet = $binet->get(new PlLimit($max));
     $course = new GroupFilter(new PFC_And(new GFC_Namespace(Group::NS_COURSE), $except), new GFO_Score(true));
     $course = $course->get(new PlLimit($max));
     $free = new GroupFilter(new PFC_And(new GFC_Namespace(Group::NS_FREE), $except), new GFO_Score(true));
     $free = $free->get(new PlLimit($max));
     // Load associated datas
     $temp = new Collection('Group');
     $temp->merge($binet)->merge($course)->merge($free);
     $temp->select(GroupSelect::base());
     // Fetch the total count of groups
     $allf = new GroupFilter(new GFC_Visible());
     $total = $allf->getTotalCount();
     $user_binet = S::user()->castes()->groups()->filter('ns', Group::NS_BINET)->remove($binet);
     $page->assign('binet', $binet);
     $page->assign('user_binet', $user_binet);
     $user_course = S::user()->castes()->groups()->filter('ns', Group::NS_COURSE)->remove($course);
     $page->assign('course', $course);
     $page->assign('user_course', $user_course);
     $user_free = S::user()->castes()->groups()->filter('ns', Group::NS_FREE)->remove($free);
     $page->assign('free', $free);
     $page->assign('user_free', $user_free);
     $page->assign('user', S::user());
     $page->assign('total', $total);
     $page->assign('title', 'Groupes');
     $page->changeTpl('groups/groups.tpl');
     $page->addCssLink('groups.css');
 }
开发者ID:netixx,项目名称:frankiz,代码行数:36,代码来源:groups.php

示例8: testMergeCollection

 public function testMergeCollection()
 {
     $this->collection->merge(new Collection(['test']));
     $this->assertEquals(5, $this->collection->count());
     $this->assertEquals('test', $this->collection->last());
 }
开发者ID:dtkahl,项目名称:php-array-tools,代码行数:6,代码来源:CollectionTest.php

示例9: targetCastes

 public function targetCastes()
 {
     $target_castes = new Collection();
     $target_castes->merge($this->castes(Rights::restricted()));
     $target_castes->merge($this->castes(Rights::everybody()));
     return $target_castes;
 }
开发者ID:netixx,项目名称:frankiz,代码行数:7,代码来源:user.php

示例10: __call

 public function __call($method, $arguments)
 {
     $className = $this->className;
     $inferedMethod = 'batch' . ucfirst($method);
     if (method_exists($className, $inferedMethod)) {
         // Call $className->batch$method($this->collected, ...)
         array_unshift($arguments, $this->collected);
         $r = forward_static_call_array(array($className, $inferedMethod), $arguments);
         if (!is_array($r)) {
             return $r;
         }
         $c = new Collection($className);
         if (!empty($r)) {
             $c->add($r);
         }
         return $c;
     }
     // If there is no argument, build an array with values from $collected->$method
     if (empty($arguments)) {
         $values = array_map(function ($mixed) use($method) {
             return $mixed->{$method}();
         }, $this->collected);
         // Try magic things with the schema
         $schema = Schema::get($className);
         if ($schema->isScalar($method)) {
             // Return an array of scalar values
             return $values;
         } elseif ($schema->isObject($method)) {
             // Return a collection
             return Collection::fromArray($values, $schema->objectType($method));
         } elseif ($schema->isFlagset($method)) {
             // Return a merged flagset
             $fs = new PlFlagSet();
             foreach ($values as $flags) {
                 foreach ($flags as $flag) {
                     $fs->addFlag($flag);
                 }
             }
             return $fs;
         } elseif ($schema->isCollection($method)) {
             // Return a merged collection
             $col = new Collection();
             foreach ($values as $c) {
                 $col->merge($c);
             }
             return $col;
         }
         throw new Exception("Unknown automatic field {$method} is schema for {$className}");
     }
     throw new Exception("The method {$className}::{$inferedMethod} doesn't exist");
 }
开发者ID:netixx,项目名称:frankiz,代码行数:51,代码来源:collection.php

示例11: batchLeaves

 public static function batchLeaves(array $nodes)
 {
     $leaves = new Collection();
     foreach ($nodes as $n) {
         $leaves->merge($n->leaves());
     }
     return $leaves;
 }
开发者ID:netixx,项目名称:frankiz,代码行数:8,代码来源:node.php


注:本文中的Collection::merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。