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


PHP Collection::filter方法代码示例

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


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

示例1: getAttribute

 /**
  * Get an attribute by name
  * @param string $name Attribute name
  * @return ConfigurationAttribute|null
  * @since 1.0
  */
 public function getAttribute($name, $returnValue = true)
 {
     $attribute = $this->attributes->filter(function ($attr) use($name) {
         /** @var ConfigurationAttribute $attr */
         return $attr->getName() == $name;
     })->first();
     return $returnValue && $attribute ? $attribute->getValue() : $attribute;
 }
开发者ID:jmpatricio,项目名称:notifications,代码行数:14,代码来源:Configuration.php

示例2: filterColumns

 protected function filterColumns($filters)
 {
     foreach ($filters as $key => $filter) {
         $this->collection = $this->collection->filter(function ($row) use($key, $filter) {
             return strpos(Str::lower($row[$key]), Str::lower($filter)) !== false;
         });
     }
 }
开发者ID:mikelmi,项目名称:mks-smart-table,代码行数:8,代码来源:CollectionEngine.php

示例3: reportFilter

 /**
  * @param Account    $account
  * @param Collection $startSet
  * @param Collection $endSet
  * @param Collection $backupSet
  *
  * @return Account
  */
 public static function reportFilter(Account $account, Collection $startSet, Collection $endSet, Collection $backupSet)
 {
     // The balance for today always incorporates transactions made on today. So to get todays "start" balance, we sub one day.
     $account->startBalance = '0';
     $account->endBalance = '0';
     $currentStart = $startSet->filter(function (Account $entry) use($account) {
         return $account->id == $entry->id;
     });
     $currentBackup = $backupSet->filter(function (Account $entry) use($account) {
         return $account->id == $entry->id;
     });
     // first try to set from backup
     if (!is_null($currentBackup->first())) {
         $account->startBalance = $currentBackup->first()->balance;
     }
     // overrule with data from start
     if (!is_null($currentStart->first())) {
         $account->startBalance = $currentStart->first()->balance;
     }
     $currentEnd = $endSet->filter(function (Account $entry) use($account) {
         return $account->id == $entry->id;
     });
     if (!is_null($currentEnd->first())) {
         $account->endBalance = $currentEnd->first()->balance;
     }
     return $account;
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:35,代码来源:AccountReportHelper.php

示例4: columnSearch

 /**
  * Perform column search.
  *
  * @return void
  */
 public function columnSearch()
 {
     $columns = $this->request->get('columns');
     for ($i = 0, $c = count($columns); $i < $c; $i++) {
         if ($this->request->isColumnSearchable($i)) {
             $this->isFilterApplied = true;
             $regex = $this->request->isRegex($i);
             $column = $this->getColumnName($i);
             $keyword = $this->request->columnKeyword($i);
             $this->collection = $this->collection->filter(function ($row) use($column, $keyword, $regex) {
                 $data = $this->serialize($row);
                 $value = Arr::get($data, $column);
                 if ($this->isCaseInsensitive()) {
                     if ($regex) {
                         return preg_match('/' . $keyword . '/i', $value) == 1;
                     } else {
                         return strpos(Str::lower($value), Str::lower($keyword)) !== false;
                     }
                 } else {
                     if ($regex) {
                         return preg_match('/' . $keyword . '/', $value) == 1;
                     } else {
                         return strpos($value, $keyword) !== false;
                     }
                 }
             });
         }
     }
 }
开发者ID:yajra,项目名称:laravel-datatables-oracle,代码行数:34,代码来源:CollectionEngine.php

示例5: getGroup

 /**
  * @param $name
  * @return Collection
  */
 public function getGroup($name)
 {
     $group = $this->collection->filter(function ($widget) use($name) {
         return $widget->group == $name;
     });
     return $group->sortBy('order');
 }
开发者ID:vanchelo,项目名称:laravel-grouped-widgets,代码行数:11,代码来源:Manager.php

示例6: generateMenu

 /**
  * @return Collection
  */
 public function generateMenu()
 {
     $menu = new Collection();
     if (!$this->auth->getUser()) {
         return $menu;
     }
     if (config('shapeshifter.menu')) {
         foreach (config('shapeshifter.menu') as $item) {
             $item = $this->parseItem($item);
             $menu->push($item);
         }
     } else {
         foreach ($this->modules->getOrdered() as $module) {
             $attributes = $module->json()->getAttributes();
             $item = $this->parseItem($attributes);
             $menu->push($item);
         }
     }
     return $menu->filter(function ($item) {
         return $this->hasAccessToRoute($item['route']);
     })->map(function ($item) {
         $item['children'] = array_filter($item['children'], function ($item) {
             return $this->hasAccessToRoute($item['route']);
         });
         return $item;
     })->filter(function ($item) {
         return $this->hasAccessToRoute('superuser') || count($item['children']) === 0 && $item['route'] !== null;
     });
 }
开发者ID:wearejust,项目名称:shapeshifter,代码行数:32,代码来源:MenuService.php

示例7: applyFilterToMediaCollection

 /**
  * Apply given filters on media.
  *
  * @param \Illuminate\Support\Collection $media
  * @param array|callable                 $filter
  *
  * @return Collection
  */
 protected function applyFilterToMediaCollection(Collection $media, $filter) : Collection
 {
     if (is_array($filter)) {
         $filter = $this->getDefaultFilterFunction($filter);
     }
     return $media->filter($filter);
 }
开发者ID:spatie,项目名称:laravel-medialibrary,代码行数:15,代码来源:MediaRepository.php

示例8: cleanCollection

 /**
  * Delete all elements which are all keys is null
  * 
  * @return void
  */
 private function cleanCollection()
 {
     $this->collection = $this->collection->filter(function (Element $item) {
         if (!$item->allKeyNull()) {
             return true;
         }
     });
 }
开发者ID:muratsplat,项目名称:multilang,代码行数:13,代码来源:Picker.php

示例9: getTypeByClassName

 /**
  * @param string $needleClass
  *
  * @return string|null
  */
 public function getTypeByClassName($needleClass)
 {
     $type = $this->types->filter(function (\KodiCMS\Widgets\Contracts\WidgetType $type) use($needleClass) {
         return $type->getClass() == $needleClass or $this->isCorrupt($type->getClass());
     })->first();
     if ($type) {
         return $type->getType();
     }
 }
开发者ID:KodiComponents,项目名称:module-widgets,代码行数:14,代码来源:WidgetManager.php

示例10: getNotUndoRunningCommandCollection

 /**
  * Return a Collection of all Commands that have not running the undo action
  * @return static
  */
 protected function getNotUndoRunningCommandCollection()
 {
     return $this->commands->filter(function ($item) {
         $value = $item->isUndoRun();
         if ($value === false) {
             return $item;
         }
     });
 }
开发者ID:TheCodeEngine,项目名称:pipeline-develop,代码行数:13,代码来源:Pipeline.php

示例11: index

 /**
  * Show the application welcome screen to the user.
  *
  * @return mixed
  */
 public function index()
 {
     $name = app('orchestra.app')->installed() ? 'welcome' : 'hello';
     $packages = new Collection(config('website.packages', []));
     $components = $packages->filter(function ($package) {
         return in_array('component', $package['type']);
     });
     return view($name, compact('packages', 'components'));
 }
开发者ID:stevebauman,项目名称:orchestraplatform.com,代码行数:14,代码来源:WelcomeController.php

示例12: updateFieldProperty

 /**
  * Activate a boolean property for the given fields.
  * @param $property string fillable|guarded|in_table, etc
  * @param $arguments array|string - * if all fields
  * @return $this
  */
 protected function updateFieldProperty($property, $arguments)
 {
     $fields = $arguments == "*" ? $this->fields : $this->fields->filter(function (FieldBlueprint $field) use($arguments) {
         return in_array($field->getName(), $arguments);
     });
     $fields->each(function (FieldBlueprint $field) use($property) {
         $field->setProperty($property, true);
     });
     return $this;
 }
开发者ID:breachofmind,项目名称:birdmin,代码行数:16,代码来源:ModelBlueprint.php

示例13: directoriesUsedByBackupJob

 protected function directoriesUsedByBackupJob() : array
 {
     return $this->backupDestinations->filter(function (BackupDestination $backupDestination) {
         return $backupDestination->filesystemType() === 'local';
     })->map(function (BackupDestination $backupDestination) {
         return $backupDestination->disk()->getDriver()->getAdapter()->applyPathPrefix('');
     })->each(function (string $localDiskRootDirectory) {
         $this->fileSelection->excludeFilesFrom($localDiskRootDirectory);
     })->push($this->temporaryDirectory->path())->toArray();
 }
开发者ID:spatie,项目名称:laravel-backup,代码行数:10,代码来源:BackupJob.php

示例14: getPrefixes

 /**
  * Search for any prefixes attached to this route.
  *
  * @return string
  */
 protected function getPrefixes()
 {
     $router = app(\Illuminate\Routing\Router::class);
     $this->prefixes = collect(explode('/', $router->getCurrentRoute()->getPrefix()));
     // Remove the last prefix if it matches the controller.
     $this->prefixes = $this->removeControllerFromPrefixes($this->prefixes);
     if ($this->prefixes->count() > 0) {
         $this->prefix = $this->prefixes->filter()->implode('.');
     }
 }
开发者ID:nukacode,项目名称:core,代码行数:15,代码来源:ViewModel.php

示例15: doInternalSearch

 private function doInternalSearch(Collection $columns, array $searchColumns)
 {
     if (is_null($this->search) or empty($this->search)) {
         return;
     }
     $value = $this->search;
     $caseSensitive = $this->options['caseSensitive'];
     $toSearch = array();
     // Map the searchColumns to the real columns
     $ii = 0;
     foreach ($columns as $i => $col) {
         if (in_array($columns->get($i)->getName(), $searchColumns)) {
             $toSearch[] = $ii;
         }
         $ii++;
     }
     $self = $this;
     $this->workingCollection = $this->workingCollection->filter(function ($row) use($value, $toSearch, $caseSensitive, $self) {
         for ($i = 0; $i < count($row); $i++) {
             if (!in_array($i, $toSearch)) {
                 continue;
             }
             $column = $i;
             if ($self->getAliasMapping()) {
                 $column = $self->getNameByIndex($i);
             }
             if ($self->getOption('stripSearch')) {
                 $search = strip_tags($row[$column]);
             } else {
                 $search = $row[$column];
             }
             if ($caseSensitive) {
                 if ($self->exactWordSearch) {
                     if ($value === $search) {
                         return true;
                     }
                 } else {
                     if (str_contains($search, $value)) {
                         return true;
                     }
                 }
             } else {
                 if ($self->getExactWordSearch()) {
                     if (strtolower($value) === strtolower($search)) {
                         return true;
                     }
                 } else {
                     if (str_contains(strtolower($search), strtolower($value))) {
                         return true;
                     }
                 }
             }
         }
     });
 }
开发者ID:Cyber-Duck,项目名称:Datatable,代码行数:55,代码来源:CollectionEngine.php


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