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


PHP Collection::each方法代码示例

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


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

示例1: getInitial

 public function getInitial()
 {
     $words = new Collection(explode(' ', $this->name));
     // if name contains single word, use first N character
     if ($words->count() === 1) {
         if ($this->name->length() >= $this->length) {
             return $this->name->substr(0, $this->length);
         }
         return (string) $words->first();
     }
     // otherwise, use initial char from each word
     $initials = new Collection();
     $words->each(function ($word) use($initials) {
         $initials->push(Stringy::create($word)->substr(0, 1));
     });
     return $initials->slice(0, $this->length)->implode('');
 }
开发者ID:explore-laravel,项目名称:avatar,代码行数:17,代码来源:InitialGenerator.php

示例2: __invoke

 /**
  * На самом деле тут у меня фантация играет по полной, поймать мошеника это круто
  * можно было реализовать из hidden risk некую битовую маску и по ней уже обсчитывать мошеников
  * @param Collection $leaders
  * @param []Collection $prevLeaders
  * @return []Collection
  */
 public function __invoke(Collection $leaders, array $prevLeaders)
 {
     $leaders->each(function ($value) use($prevLeaders) {
         $id = object_get($value, 'id', null);
         $score = object_get($value, 'score', null);
         // Идем по списку лидеров
         foreach ($prevLeaders as $leaders) {
             $leaders->each(function ($leader) use($id, $score) {
                 // Если личдер найден
                 if ($leader->id === $id) {
                     // И он есть в  hidden risk
                     if (isset($this->hidRisk[$id])) {
                         // Удаляем его
                         unset($this->hidRisk[$id]);
                     }
                     // Если сейчас у него очков больше чем в прошлый раз
                     if ($leader->score < $score / static::RISK_GROWTH_SCOPE) {
                         $this->result[$id] = $leader;
                     } else {
                         $this->hidRisk[$id] = $leader;
                     }
                 }
             });
         }
         if (isset($this->hidRisk[$id])) {
             $this->result[$id] = $value;
         }
     });
     return $this->result;
 }
开发者ID:ftob,项目名称:php-leaderboard-bundle,代码行数:37,代码来源:GetAbnormalLeaders.php

示例3: scrape

 /**
  * Start the site Scraping process.
  *
  * @return void
  */
 public function scrape()
 {
     $scrape = new Scrape(new Client());
     $this->list->each(function ($url) use($scrape) {
         $this->writePage($url, $scrape->run($url));
     });
 }
开发者ID:jjpmann,项目名称:static-sites,代码行数:12,代码来源:Scraper.php

示例4: setUp

 /**
  * Set up test environment.
  */
 public function setUp()
 {
     parent::setUp();
     $this->company = factory(Company::class)->create();
     $this->users = factory(User::class, 5)->create(['company_id' => $this->company->id]);
     $this->users->each(function ($user) {
         factory(Task::class, 5)->create(['user_id' => $user->id]);
     });
 }
开发者ID:nuwave,项目名称:lighthouse,代码行数:12,代码来源:DataLoaderTest.php

示例5: tearDown

 public function tearDown()
 {
     $this->filesCreated->each(function ($file) {
         try {
             unlink($file);
         } catch (Exception $e) {
         }
     });
     parent::tearDown();
 }
开发者ID:talv86,项目名称:easel,代码行数:10,代码来源:PostFormFieldsTest.php

示例6: placeWidgetsToLayoutBlocks

 /**
  * @return void
  */
 public function placeWidgetsToLayoutBlocks()
 {
     $this->sortWidgets();
     $this->registeredWidgets->each(function (WidgetCollectionItem $widget) {
         if (method_exists($widget->getObject(), 'onLoad')) {
             app()->call([$widget->getObject(), 'onLoad']);
         }
     })->each(function (WidgetCollectionItem $widget) {
         if (method_exists($widget->getObject(), 'afterLoad')) {
             app()->call([$widget->getObject(), 'afterLoad']);
         }
     });
 }
开发者ID:KodiComponents,项目名称:module-widgets,代码行数:16,代码来源:WidgetCollection.php

示例7: compileLess

 /**
  * @param \Illuminate\Support\Collection $files
  * @return string
  */
 public function compileLess($files)
 {
     $files->each(function ($value) {
         $this->less->parseFile($value);
     });
     return $this->less->getCss();
 }
开发者ID:darrengopower,项目名称:framework,代码行数:11,代码来源:Compiler.php

示例8: cleanUp

 protected function cleanUp(Collection $cleanableModels)
 {
     $cleanableModels->each(function (string $modelClass) {
         $numberOfDeletedRecords = $modelClass::cleanUp($modelClass::query())->delete();
         event(new ModelWasCleanedUp($modelClass, $numberOfDeletedRecords));
         $this->info("Deleted {$numberOfDeletedRecords} record(s) from {$modelClass}.");
     });
 }
开发者ID:spatie,项目名称:laravel-model-cleanup,代码行数:8,代码来源:CleanUpModelsCommand.php

示例9: handle

 /**
  * Execute the job.
  *
  * @return Collection
  */
 public function handle()
 {
     for ($i = 1; $i <= $this->amount; $i++) {
         $this->codes->push($this->generateCode());
     }
     $this->checkDatabase();
     /** @var \Illuminate\Database\Eloquent\Collection $products */
     $products = collect();
     /**
      * Now it is safe to add to the DB
      */
     $this->codes->each(function ($code) use($products) {
         $products->push(new Code(compact('code')));
     });
     $this->product->codes()->saveMany($products);
     return $products;
 }
开发者ID:SkysoulDesign,项目名称:mirage.dev,代码行数:22,代码来源:GenerateCodesCommand.php

示例10: toArray

 /**
  * Get the array representation of attributes
  * @return array Assoc array with attribute name in the key
  * @since 1.0
  */
 public function toArray()
 {
     $returnArr = [];
     $this->attributes->each(function ($attribute) use(&$returnArr) {
         /* @var ConfigurationAttribute $attribute **/
         $returnArr[$attribute->getName()] = $attribute->getValue();
     });
     return $returnArr;
 }
开发者ID:jmpatricio,项目名称:notifications,代码行数:14,代码来源:Configuration.php

示例11: run

 public function run()
 {
     $this->backupDestinations->each(function (BackupDestination $backupDestination) {
         try {
             if (!$backupDestination->isReachable()) {
                 throw new Exception("Could not connect to disk {$backupDestination->diskName()} because: {$backupDestination->connectionError()}");
             }
             consoleOutput()->info("Cleaning backups of {$backupDestination->backupName()} on disk {$backupDestination->diskName()}...");
             $this->strategy->deleteOldBackups($backupDestination->backups());
             event(new CleanupWasSuccessful($backupDestination));
             $usedStorage = Format::humanReadableSize($backupDestination->usedStorage());
             consoleOutput()->info("Used storage after cleanup: {$usedStorage}.");
         } catch (Exception $exception) {
             consoleOutput()->error("Cleanup failed because: {$exception->getMessage()}.");
             event(new CleanupHasFailed($exception));
         }
     });
 }
开发者ID:spatie,项目名称:laravel-backup,代码行数:18,代码来源:CleanupJob.php

示例12: __invoke

 /**
  * @param Collection $leaders
  * @param []Collection $prevLeaders Массив ранее собраных списков
  * @return array
  */
 public function __invoke(Collection $leaders, array $prevLeaders)
 {
     $leaders->each(function ($value) use($prevLeaders) {
         $id = object_get($value, 'id', null);
         $place = object_get($value, 'place', null);
         $this->result[$id] = 0;
         foreach ($prevLeaders as $leaders) {
             $leaders->each(function ($value) use($id, $place) {
                 if ($value->id === $id) {
                     if ($value->place !== $place) {
                         $this->result[$id]++;
                     }
                 }
             });
         }
     });
     return $this->result;
 }
开发者ID:ftob,项目名称:php-leaderboard-bundle,代码行数:23,代码来源:ChangesInTheNumberOfPositions.php

示例13: saveChannels

 public function saveChannels(Collection $data)
 {
     $data->each(function ($item, $key) {
         $item->persist();
         $game = $this->game->get($item->relatedGame);
         if (!is_null($game)) {
             $item->relatesToGame($game);
         }
     });
 }
开发者ID:Gamespectre,项目名称:spectator-api,代码行数:10,代码来源:YoutubeRepository.php

示例14: send

 /**
  * Send the notification to devices.
  * Returns errors (APNs and GCM) and updated token (GCM).
  *
  * @return array [ 'errors': [ Device, ... ], 'updates' => [ [ 'device' => Device, 'token' => 'a-new-token' ], ... ] ]
  */
 public function send()
 {
     $apns = new Collection();
     $gcm = new Collection();
     $this->devices->each(function (Device $device) use(&$apns, &$gcm) {
         if ($device->isApns()) {
             $apns->push($this->merge($device));
         } elseif ($device->isGcm()) {
             $gcm->push($this->merge($device));
         }
     });
     $results = ['errors' => [], 'updates' => []];
     $this->mergeResults($results, $this->pushApns($apns));
     $this->mergeResults($results, $this->pushGcm($gcm));
     // Reset
     $apns = null;
     $gcm = null;
     $this->device = new Collection();
     return $results;
 }
开发者ID:bnbwebexpertise,项目名称:laravel-push-notifications,代码行数:26,代码来源:Notification.php

示例15: removeBackupsForAllPeriodsExceptOne

 protected function removeBackupsForAllPeriodsExceptOne(Collection $backupsPerPeriod)
 {
     $backupsPerPeriod->each(function (Collection $groupedBackupsByDateProperty, string $periodName) {
         $groupedBackupsByDateProperty->each(function (Collection $group) {
             $group->shift();
             $group->each(function (Backup $backup) {
                 $backup->delete();
             });
         });
     });
 }
开发者ID:spatie,项目名称:laravel-backup,代码行数:11,代码来源:DefaultStrategy.php


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