/** * @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]); }
/** * 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; }
/** * @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; }
/** 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); }
/** * 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; }
/** * 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; }
/** * 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); }
/** * @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; }
/** * 两个集合的差集,集合数据只能是一维形式,不能是多维的 * $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'); }
/** * 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(); }); }
/** * Adds multiple items to the menu. * * @param array $items */ public function addItems(array $items) { $this->items = $this->items->merge($this->createItems($items)); }
public function merge($events) { $this->events = $this->events->merge($events); }
/** * @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'; }
/** * @param $method */ private function updateUsages(Method $method) { $this->uses = $this->uses->merge($method->getUses()); $this->uses->push($method->getRequestClass()); }
public function ponerEnCola($pedidos) { $this->lista = $this->lista->merge($pedidos); \Cache::put($this->keyCola, $this->lista, 1440); }
/** * Do not included the given files and directories. * * @param array|string $excludeFilesAndDirectories * * @return \Spatie\Backup\Tasks\Backup\FileSelection */ public function excludeFilesFrom($excludeFilesAndDirectories) : FileSelection { $this->excludeFilesAndDirectories = $this->excludeFilesAndDirectories->merge($this->sanitize($excludeFilesAndDirectories)); return $this; }
public function testMergeCollection() { $c = new Collection(['name' => 'Hello']); $this->assertEquals(['name' => 'World', 'id' => 1], $c->merge(new Collection(['name' => 'World', 'id' => 1]))->all()); }
/** * Merge the collection with the given items. * * @param mixed $items * * @return static */ public function merge($items) { //Parent merge return parent::merge($this->filterOutUnsupported($items)); }