本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
示例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']]);
}
示例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');
}
示例8: testMergeCollection
public function testMergeCollection()
{
$this->collection->merge(new Collection(['test']));
$this->assertEquals(5, $this->collection->count());
$this->assertEquals('test', $this->collection->last());
}
示例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;
}
示例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");
}
示例11: batchLeaves
public static function batchLeaves(array $nodes)
{
$leaves = new Collection();
foreach ($nodes as $n) {
$leaves->merge($n->leaves());
}
return $leaves;
}