/** * Modules of installed or not installed. * * @param bool $installed * * @return \Illuminate\Support\Collection */ public function getModules($installed = false) { if ($this->modules->isEmpty()) { if ($this->files->isDirectory($this->getModulePath()) && !empty($directories = $this->files->directories($this->getModulePath()))) { (new Collection($directories))->each(function ($directory) use($installed) { if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) { $package = new Collection(json_decode($this->files->get($file), true)); if (Arr::get($package, 'type') == 'notadd-module' && ($name = Arr::get($package, 'name'))) { $module = new Module($name); $module->setAuthor(Arr::get($package, 'authors')); $module->setDescription(Arr::get($package, 'description')); if ($installed) { $module->setInstalled($installed); } if ($entries = data_get($package, 'autoload.psr-4')) { foreach ($entries as $namespace => $entry) { $module->setEntry($namespace . 'ModuleServiceProvider'); } } $this->modules->put($directory, $module); } } }); } } return $this->modules; }
/** * Extension list. * * @return \Illuminate\Support\Collection * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function getExtensions() { if ($this->extensions->isEmpty()) { if ($this->files->isDirectory($this->getExtensionPath()) && !empty($vendors = $this->files->directories($this->getExtensionPath()))) { collect($vendors)->each(function ($vendor) { if ($this->files->isDirectory($vendor) && !empty($directories = $this->files->directories($vendor))) { collect($directories)->each(function ($directory) { if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) { $package = new Collection(json_decode($this->files->get($file), true)); if (Arr::get($package, 'type') == 'notadd-extension' && ($name = Arr::get($package, 'name'))) { $extension = new Extension($name); $extension->setAuthor(Arr::get($package, 'authors')); $extension->setDescription(Arr::get($package, 'description')); if ($entries = data_get($package, 'autoload.psr-4')) { foreach ($entries as $namespace => $entry) { $extension->setEntry($namespace . 'Extension'); } } $this->extensions->put($directory, $extension); } } }); } }); } } return $this->extensions; }
/** * Get the winner of the Round * @return bool|Player */ public function victor() { if ($this->battles->isEmpty()) { return false; } return $this->battles->last()->victor(); }
/** * @param GrantableInterface $grantable * * @return array */ public function getAllPermissions(GrantableInterface $grantable) { if (is_null($this->permissions) || $this->permissions->isEmpty()) { $this->initialize($grantable); } $result = $this->permissions->all(); array_filter($result, function ($item) { return $item; }); return array_keys($result); }
/** * Runs the result for retrieval calls to the repository * through postprocessing. * * @param Collection|Model|null $result the result of the query, ready for postprocessing * @return Model|Collection|null */ public function postProcess($result) { // determine whether there is anything to process if (is_null($result) || is_a($result, Collection::class) && $result->isEmpty()) { return $result; } // check if there is anything to do process it through if ($this->postProcessors->isEmpty()) { return $result; } // for each Model, instantiate and apply the processors if (is_a($result, Collection::class)) { $result->transform(function ($model) { return $this->applyPostProcessorsToModel($model); }); } elseif (is_a($result, AbstractPaginator::class)) { // result is paginate() result // do not apply postprocessing for now (how would we even do it?) return $result; } else { // result is a model $result = $this->applyPostProcessorsToModel($result); } return $result; }
/** * @param Collection $collection * @return Collection */ public function apply(Collection $collection) { if (!$collection->isEmpty() && !empty($this->criteria)) { foreach ($this->criteria as $key => $parameters) { // Парамментры могут быть пустыми if (empty($parameters)) { continue; } // Фильтруем значение $collection = $collection->filter(function ($value, $k) use($key, $parameters) { foreach ($parameters as $param) { // Получем опреатор в зависимости от ключа $exp = $this->getSign($key); /** @var Parameters $param*/ if (count($param->getAttributes()) === 2) { $attributes = $param->getAttributes(); return eval('return $value->{head($attributes)}' . $exp . ' $value->{last($attributes)};'); } else { if (count($param->getAttributes()) === 1 && !empty($param->getValue())) { return eval('return $value->{head($param->getAttributes())} ' . $exp . ' $param->getValue();'); } } } return false; }); } } return $collection; }
public function validate() { if ($this->row_orders->isEmpty()) { $this->errors->add("row_orders", L::t("There is no product in the cart.")); return false; } return true; }
private function determineBaseline() { $baselines = BaselineFile::account($this->account)->orderBy('path', 'asc')->get(); //-- convert to File::class $this->baseline = BaselineFile::toFiles($baselines); if ($this->baseline->isEmpty() && !$this->first_scan) { $this->alert("**Probable Compromise**<br> Empty baseline table (ALL baseline files are missing or deleted)!"); } }
public function getFromIds(Collection $idCollection, $method, $force = false) { if ($idCollection->isEmpty()) { return $idCollection; } return $idCollection->unique()->map(function ($item, $key) use($force, $method) { return call_user_func([$this, $method], $item, $force); }); }
/** * Bind a collection to a transformer and start building a response. * * @param \Illuminate\Support\Collection $collection * @param object $transformer * @param array $parameters * @param \Closure $after * * @return \Dingo\Api\Http\ResponseBuilder */ public function collection(Collection $collection, $transformer, array $parameters = [], Closure $after = null) { if ($collection->isEmpty()) { $class = get_class($collection); } else { $class = get_class($collection->first()); } $binding = $this->transformer->register($class, $transformer, $parameters, $after); return new ResponseBuilder($collection, $binding); }
/** * @return \Illuminate\Support\Collection * @throws \Artem328\LaravelYandexKassa\Exceptions\YandexKassaNoPaymentTypesProvidedException */ public function getPaymentTypes() { if ($this->paymentTypes === null) { $this->paymentTypes = collect(config('yandex_kassa.payment_types', [])); } if ($this->paymentTypes->isEmpty()) { throw new YandexKassaNoPaymentTypesProvidedException(); } return $this->paymentTypes; }
/** * Gets the current flash level * and message using accessor methods. * * @param string $attribute * @return string|null */ public function __get($attribute) { if ($this->current->isEmpty()) { return null; } $getter = 'get' . $attribute; if (method_exists($this, $getter)) { return $this->{$getter}(); } return null; }
/** * Themes of installed or not installed. * * @param bool $installed * * @return \Illuminate\Support\Collection */ public function getThemes($installed = false) { if ($this->themes->isEmpty()) { if ($this->files->isDirectory($this->getThemePath()) && !empty($directories = $this->files->directories($this->getThemePath()))) { (new Collection($directories))->each(function ($directory) use($installed) { if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) { $package = new Collection(json_decode($this->files->get($file), true)); if (Arr::get($package, 'type') == 'notadd-extension' && ($name = Arr::get($package, 'name'))) { $module = new Theme($name, Arr::get($package, 'authors'), Arr::get($package, 'description')); if ($installed) { $module->setInstalled($installed); } $this->themes->put($directory, $module); } } }); } } return $this->themes; }
/** * Output the collection assets * @param \Illuminate\Support\Collection $collection * @param string $type * @return string */ public function outputAssets($collection, $type) { if (!$collection->isEmpty()) { $link = $this->determineLinkingAttribute($type); $output = array(); foreach ($collection->all() as $name => $attr) { $output[$name] = $this->createAssetTag($type, $link, $attr); } return implode($output, ''); } }
/** * Set the table name or get the table name. * @param $name string * @return $this|string */ public function table($name = null) { if (!$name) { return $this->table; } $this->table = $name; if ($this->labels->isEmpty()) { $this->guessLabels($name); } return $this; }
/** * @return \Generator|string[] */ public function selectedFiles() { if ($this->includeFilesAndDirectories->isEmpty()) { return []; } $finder = (new Finder())->ignoreDotFiles(false)->ignoreVCS(false)->files(); if ($this->shouldFollowLinks) { $finder->followLinks(); } $finder->in($this->includedDirectories()); foreach ($this->includedFiles() as $includedFile) { (yield $includedFile); } foreach ($finder->getIterator() as $file) { if ($this->shouldExclude($file)) { continue; } (yield $file->getPathname()); } }
public function getVideosForPlaylists(Collection $playlists, $force = false) { if ($playlists->isEmpty()) { return $playlists; } $videos = collect([]); $playlists->map(function ($item) { return $item->id; })->unique()->each(function ($item) use(&$videos, $force) { $videos = $this->getVideosInPlaylist($item, $force)->merge($videos->all()); }); return $videos; }
/** * @return \Illuminate\Support\Collection */ public function getExtensions() { if ($this->extensions->isEmpty()) { $this->getExtensionPaths()->each(function ($directory, $key) { if ($this->container->make(SettingsRepository::class)->get('extension.' . $key . '.installed')) { if ($this->filesystem->exists($bootstrap = $directory . DIRECTORY_SEPARATOR . 'bootstrap.php')) { $extension = $this->filesystem->getRequire($bootstrap); if (is_string($extension) && in_array(ExtensionRegistrar::class, class_parents($extension))) { $registrar = $this->container->make($extension); $extension = $registrar->getExtension(); } if ($extension instanceof Extension) { $this->extensions->put($extension->getId(), $extension); } } } }); } return $this->extensions; }
/** * executes the command */ protected function handle() { $client = $this->getClient(); $project = $this->argument('project'); if (null === $project) { $command = new IndexCommand(); } else { $command = (new RelatedTasksCommand())->setId($this->resolveProjectId($project)); } try { $response = $client->send($command); } catch (ClientException $e) { if ($e->getCode() === 401) { $this->callSilent('dpm:token'); $client->setToken($this->getApplication()->resetConfig()->config()->get('token')); $response = $client->send($command); } else { $this->error($e->getMessage()); return 1; } } if ($response->getStatusCode() >= 300) { $this->info('No Tasks found'); return 0; } $responseData = json_decode($response->getBody()->getContents(), true); $tasksData = array_get($responseData, 'data', []); $includedData = array_get($responseData, 'included', []); $tasks = new Collection($tasksData); if ($tasks->isEmpty()) { $this->info('No tasks found'); return 0; } $output = $this->output; $renderer = new TaskRenderer($output, $includedData); $this->getFilteredOrderedTasks($tasks)->each(function ($task) use($renderer) { $renderer->setTask($task)->writeln(); }); return 0; }
/** * resolveProjects * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ protected function resolveProjects() { if (!$this->projects->isEmpty()) { return; } /** * @var \Codex\Codex\Menus\Node $projectsMenu */ $projectsMenu = $this->menus->add('projects_menu'); $finder = new Finder(); $projects = $finder->in($this->rootDir)->files()->name('config.php')->depth('<= 1')->followLinks(); foreach ($projects as $projectDir) { /** @var \SplFileInfo $projectDir */ $name = Path::getDirectoryName($projectDir->getPath()); $config = $this->container->make('fs')->getRequire($projectDir->getRealPath()); $config = array_replace_recursive($this->config('default_project_config'), $config); $project = $this->container->make(Project::class, ['factory' => $this, 'name' => $name, 'config' => $config]); $this->runHook('project:make', [$this, $project]); $this->projects->put($name, $project); $projectsMenu->add($name, $name, 'root', [], ['href' => $this->url($project)]); } }
/** * Determine if the list of items is empty or not. * * @return bool */ public function isEmpty() { return $this->items->isEmpty(); }
public function testEmptyCollectionIsEmpty() { $c = new Collection(); $this->assertTrue($c->isEmpty()); }
/** * After applying, removes the criteria that should only have applied once */ protected function clearOnceCriteria() { if (!$this->onceCriteria->isEmpty()) { $this->onceCriteria = new Collection(); } }
public function hasItems() { return !$this->subitems_collection->isEmpty(); }
public function isEmpty() { return $this->buzzes->isEmpty(); }
/** * Check for empty response * * @param Collection $results * @return mixed */ private function checkForResponse(Collection $results) { if ($results->isEmpty()) { throw new NotFoundException("Not found"); } }
public function any() { return !$this->messages->isEmpty(); }
/** * Get the documents for the specified collection. * * @param \Illuminate\Support\Collection $collection * @return array */ public function getDocumentsForModels(BaseCollection $collection, $fields = null) { if ($collection->isEmpty()) { return []; } $this->validateModelClass($collection->first()); $all = $collection->all(); // Create a dictionary for model collection. $modelIds = array_map(function ($m) { return $m->getIndexKey(); }, $all); $params = $this->getBaseParams(); $params['body']['ids'] = $modelIds; if (!is_null($fields)) { $params['_source'] = $fields; } $results = $this->client->mget($params); $this->checkMultiGetResults($results, $collection); return $results['docs']; }
/** * Bind a collection to a transformer and start building a response. * * @param \Illuminate\Support\Collection $collection * @param object $transformer * @param array|\Closure $parameters * @param \Closure|null $after * * @return \Dingo\Api\Http\Response */ public function collection(Collection $collection, $transformer, $parameters = [], Closure $after = null) { if ($collection->isEmpty()) { $class = get_class($collection); } else { $class = get_class($collection->first()); } if ($parameters instanceof \Closure) { $after = $parameters; $parameters = []; } $binding = $this->transformer->register($class, $transformer, $parameters, $after); return new Response($collection, 200, [], $binding); }