本文整理汇总了PHP中Illuminate\Support\Collection::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::merge方法的具体用法?PHP Collection::merge怎么用?PHP Collection::merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* @param \Notadd\Foundation\Extension\ExtensionManager $manager
*/
public function boot(ExtensionManager $manager)
{
if ($this->app->isInstalled()) {
$manager->getExtensions()->each(function (Extension $extension) use($manager) {
$registrar = $extension->getRegistrar();
static::$complies = static::$complies->merge($registrar->compiles());
$this->commands($registrar->loadCommands());
(new Collection($registrar->loadLocalizationsFrom()))->each(function ($path, $namespace) {
$this->loadTranslationsFrom($path, $namespace);
});
(new Collection($registrar->loadMigrationsFrom()))->each(function ($paths) {
$this->loadMigrationsFrom($paths);
});
(new Collection($registrar->loadPublishesFrom()))->each(function ($to, $from) {
$this->publishes([$from => $to], 'public');
});
(new Collection($registrar->loadViewsFrom()))->each(function ($path, $namespace) {
$this->loadViewsFrom($path, $namespace);
});
$extension->enable();
$this->app->make(Dispatcher::class)->fire(new ExtensionEnabled($this->app, $manager, $extension));
$manager->boot($registrar);
});
}
$this->commands([InstallCommand::class, ListCommand::class, UninstallCommand::class, UpdateCommand::class]);
}
示例2: myAllowedResources
/**
* Get all resources on which the model has the requested permission.
*
* @param string $permission_name
* @param string $resource_class_name
* @param Closure|null $resolver
*
* @return Collection
*/
public function myAllowedResources($permission_name, $resource_class_name, Closure $resolver = null)
{
$policy_instance = $this->gate->getPolicyFor($resource_class_name);
$policy_roles = $policy_instance->fortress_roles();
// Try to find Roles
$check_roles = [];
foreach ($policy_roles as $role_name => $abilities) {
if (in_array($permission_name, $abilities)) {
$check_roles[] = $role_name;
}
}
if (empty($check_roles)) {
return collect();
}
$roles = $this->roles->merge($this->relations)->filter(function ($role) use($check_roles, $resource_class_name) {
if (in_array($role->getRoleName(), $check_roles) && $role->getResourceType() === $resource_class_name) {
return true;
}
return false;
});
if ($resolver) {
return $resolver($roles);
}
$return = collect();
foreach ($roles as $role) {
$tmp = app($role->getResourceType());
$tmp = $tmp->find($role->getResourceId());
if ($tmp && $tmp->getKey()) {
$return->push($tmp);
}
}
return $return;
}
示例3: collectOldUploads
/**
* @return bool
*/
public function collectOldUploads() : bool
{
/** @var UploadCollector $uploadCollector */
$uploadCollector = app(UploadCollector::class, [$this->job]);
$uploadCollector->run();
$this->files = $this->files->merge($uploadCollector->getFiles());
return true;
}
示例4: getData
/** Returns a data forms select
*
* @param array $data
*
* @return Collection
*/
protected function getData($data)
{
$d = [];
foreach ($data as $key => $value) {
$d[] = ['id' => $key, 'name' => $value];
}
return $this->selectOption->merge($d);
}
示例5: labels
/**
* Return the labels collection or set new labels.
* @param $array array key=>value
* @return Collection|$this
*/
public function labels($array = null)
{
if (is_null($array)) {
return $this->labels;
}
$this->labels = $this->labels->merge($array);
return $this;
}
示例6: withAttribute
/**
* Add one or more named attributes with value to the current element.
* Overrides any set attributes with same name.
* Attributes evaluating to falsy will be unset.
*
* @param string|callable|array|Arrayable $attributes Attribute name as string, can also be an array of names and values, or a callable returning such an array.
* @param string|bool|callable|array|Arrayable $value to set, only used if $attributes is a string
* @return $this|FluentHtmlElement can be method-chained to modify the current element
*/
public function withAttribute($attributes, $value = true)
{
if (is_string($attributes)) {
$this->html_attributes->put($attributes, $value);
} elseif (HtmlBuilder::useAsCallable($attributes)) {
$this->html_attributes->push($attributes);
} else {
$this->html_attributes = $this->html_attributes->merge($attributes);
}
return $this;
}
示例7: schema
/**
* Generate GraphQL Schema.
*
* @return \GraphQL\Schema
*/
public function schema()
{
$schema = config('relay.schema');
$this->types->each(function ($type, $key) {
$this->type($key);
});
$queries = $this->queries->merge(array_get($schema, 'queries', []));
$mutations = $this->mutations->merge(array_get($schema, 'mutations', []));
$queryTypes = $this->generateType($queries, ['name' => 'Query']);
$mutationTypes = $this->generateType($mutations, ['name' => 'Mutation']);
return new Schema($queryTypes, $mutationTypes);
}
示例8: merge
/**
* @param mixed $items
* @param string|bool $addPath
*
* @return static
*/
public function merge($items, $addPath = false)
{
$themesPaths = $this->getThemesPaths();
/* @var $themeCollection $this */
$themeCollection = parent::merge($items);
$themeCollection->requiredFields = $this->requiredFields;
$themeCollection->exceptionOnInvalid = $this->exceptionOnInvalid;
if ($addPath !== false) {
$themesPaths[] = realpath($addPath);
}
foreach ($themesPaths as $path) {
$themeCollection->themesFolders[$path] = $path;
}
return $themeCollection;
}
示例9: diff
/**
* 两个集合的差集,集合数据只能是一维形式,不能是多维的
* $collectOne->diff($collectionTwo);
*
* 结果是:存在集合 $collectOne 中,并且不存在 $collectionTwo 的一个集合
*
* 对应的: 两个集合的 交集
*
*/
public function diff()
{
$others = collect([['product' => 'Desk', 'price' => 200], ['product' => 'book', 'price' => 10], ['product' => 'shop', 'price' => 20], ['product' => 'goods', 'price' => 100]]);
//debug($this->collection);
//多维 执行不了 报错
//$diff = $this->collection->diff($other);
// 差集
$collection = collect([1, 2, 3, 4, 5]);
$other = collect([2, 4, 6, 8]);
//一维可以执行
$diff = $collection->diff($other);
debug($diff);
// 交集
$intersect = $collection->intersect($other);
debug($intersect);
// 并集 合并后 的集合 是不管里面有没有的重复元素的,这是集合的定义决定的
$merge = $collection->merge($other);
$merge = $this->collection->merge($others);
debug($merge);
return view('index');
}
示例10: mergeUniqueCollection
/**
* Merges items to collection and preserves uniqueness by Model::getKey().
*
* @return Collection
*/
public function mergeUniqueCollection(Collection $collection, $items)
{
return $collection->merge($items)->unique(function (Model $model) {
return $model->getKey();
});
}
示例11: addItems
/**
* Adds multiple items to the menu.
*
* @param array $items
*/
public function addItems(array $items)
{
$this->items = $this->items->merge($this->createItems($items));
}
示例12: merge
public function merge($events)
{
$this->events = $this->events->merge($events);
}
示例13: compileScriptMaterial
/**
* @return \Illuminate\Support\Collection
*/
protected function compileScriptMaterial()
{
$files = new Collection();
$this->layoutJsMaterial->merge($this->defaultJsMaterial)->merge($this->extendJsMaterial)->each(function ($value) use($files) {
$files->push($this->findPath($value));
});
$code = md5($files);
$this->dispatcher->listen('kernel.handled', function () use($code, $files) {
$dictionary = new Collection();
$dictionary->push($this->application->publicPath());
$dictionary->push('cache');
$dictionary = $this->pathSplit($code, '2,2,2,2,2,2', $dictionary);
$dictionary = $dictionary->implode(DIRECTORY_SEPARATOR);
if (!$this->files->isDirectory($dictionary)) {
$this->files->makeDirectory($dictionary, 0755, true, true);
}
$file = $dictionary . DIRECTORY_SEPARATOR . Str::substr($code, 12, 20) . '.js';
$key = 'cache.script.' . $code;
if (!$this->files->exists($file) || !$this->cache->has($key) && $this->application->inDebugMode()) {
$content = $this->compileScript($files);
$expires = Carbon::now()->addMinutes(10);
$this->cache->put($key, $content, $expires);
file_put_contents($file, $content);
}
});
return $this->pathSplit($code, '2,2,2,2,2,2,20', Collection::make(['cache']))->implode('/') . '.js';
}
示例14: updateUsages
/**
* @param $method
*/
private function updateUsages(Method $method)
{
$this->uses = $this->uses->merge($method->getUses());
$this->uses->push($method->getRequestClass());
}
示例15: ponerEnCola
public function ponerEnCola($pedidos)
{
$this->lista = $this->lista->merge($pedidos);
\Cache::put($this->keyCola, $this->lista, 1440);
}