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


PHP Support\Collection类代码示例

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


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

示例1: send

 public function send(Collection $data)
 {
     $validator = $this->validator($data->toArray(), $this->type);
     if (!$validator->fails()) {
         Mailer::send("emails.{$this->type}", $data->toArray(), function ($message) use($data) {
             $fromAddress = $data->get('from_address');
             $fromName = $data->get('from_name');
             $toAddress = $data->get('to_address');
             $toName = $data->get('to_name');
             $cc = $data->get('cc[]', []);
             $bcc = $data->get('bcc[]', []);
             // Send the message
             $message->from($fromAddress, $fromName);
             $message->to($toAddress, $toName)->subject($data->get('subject'));
             foreach ($cc as $address) {
                 $message->cc($address, null);
             }
             foreach ($bcc as $address) {
                 $message->bcc($address, null);
             }
         });
     } else {
         // Validation failed
         return ['success' => 0, 'status' => "Failed to validate message", 'messages' => $validator->getMessageBag()->all(), 'data' => $data, 'type' => $this->type];
     }
     if (!count(Mailer::failures())) {
         $this->sent_at = Carbon::now();
         Log::info("Sent {$this->type} email");
         return ['success' => 1, 'status' => "successfully sent message", 'data' => $data, 'type' => $this->type];
     }
     Log::info("Failed to send {$this->type} email");
     return ['success' => 0, 'status' => "failed to send message", 'messages' => "failed to send message", 'data' => $data, 'type' => $this->type];
 }
开发者ID:wdmtech,项目名称:laravel-mail,代码行数:33,代码来源:Mail.php

示例2: page

 public static function page($collection, $perPage, $path = '')
 {
     //获取分页 的页码
     //        $currentPage=0;
     //        if(@$_SERVER['REQUEST_URI']){
     //            $page=explode("=",$_SERVER['REQUEST_URI']);
     //            if(isset($page[1])) {
     //                $currentPage = $page[1];
     //            }
     //        }else{
     //            $currentPage=0;
     //        }
     $page = LengthAwarePaginator::resolveCurrentPage();
     $currentPage = $page - 1;
     $currentPage < 0 ? $currentPage = 0 : '';
     //        echo $currentPage;
     //创建一个新的数组集合
     $collection = new Collection($collection);
     //获取分页的数据
     $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all();
     //创建一个新的分页模块
     $paginator = new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);
     //获取分页path
     $url = Request::path();
     $path ? $path : $url;
     //设置分页的path
     $paginator->setPath($path);
     return $paginator;
 }
开发者ID:liuxue5213,项目名称:laravel,代码行数:29,代码来源:ShareFun.php

示例3: apply

 /**
  * @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;
 }
开发者ID:ftob,项目名称:php-leaderboard-bundle,代码行数:33,代码来源:BaseCriteria.php

示例4: index

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $servers = Server::paginate();
     $collection = new Collection();
     foreach ($servers as $server) {
         try {
             $query = new Swat4Server($server->ip_address, $server->query_port);
             $query->query();
         } catch (\Exception $e) {
             continue;
         }
         $serverquery = json_decode($query);
         if ($serverquery->hostname == '...server is reloading or offline' || $serverquery->hostname == null || $serverquery->hostname == "" || empty($serverquery->hostname)) {
             continue;
         }
         $newserver = new Arr();
         $newserver->hostname = html_entity_decode(fixHostNameForServerList($serverquery->hostname));
         $newserver->map = $serverquery->map;
         $newserver->gametype = $serverquery->gametype;
         $newserver->version = $serverquery->patch;
         $newserver->players_current = $serverquery->players_current;
         $newserver->players_max = $serverquery->players_max;
         $newserver->ip_address = $server->ip_address;
         $newserver->join_port = $server->join_port;
         $newserver->id = $server->id;
         $newserver->rank = $server->rank;
         $collection->push($newserver);
     }
     //$collection = $collection->sortByDesc('players_current');
     $collection = $collection->sortByDesc(function ($server) {
         return $server->players_current > 0 ? $server->players_current : $server->rank;
     });
     return view('server.list')->with('servers', $collection)->with('page', $servers);
 }
开发者ID:kinnngg,项目名称:knightofsorrow,代码行数:39,代码来源:ServerController.php

示例5: 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

示例6: __construct

 /**
  * CollectionProvider constructor.
  * @param Collection $collection The collection with the initial data
  */
 public function __construct(Collection $collection)
 {
     $this->collection = $collection;
     $this->totalInitialDataCount = $collection->count();
     $this->setupSearch();
     $this->setupOrder();
 }
开发者ID:ReactionJordan,项目名称:Datatable,代码行数:11,代码来源:CollectionProvider.php

示例7: transformCollection

 /**
  * @param Collection $films
  * @return Collection
  */
 public function transformCollection(Collection $films)
 {
     $transformedFilms = $films->map(function (Film $film) {
         return ['id' => $film->id, 'title' => $film->title, 'original_title' => $film->original_title, 'years' => $film->years, 'countries' => $film->countries()->get(), 'synopsis' => $film->synopsis, 'director' => $film->director, 'created_at' => $film->created_at->toDateString(), 'cover' => ['thumbnail' => $film->image->url('thumbnail')]];
     });
     return $transformedFilms;
 }
开发者ID:filmoteca,项目名称:filmoteca,代码行数:11,代码来源:FilmTransformer.php

示例8: getAccountReport

 /**
  * This method generates a full report for the given period on all
  * given accounts.
  *
  * a special consideration for accounts that did exist on this exact day.
  * we also grab the balance from today just in case, to see if that changes things.
  * it's a fall back for users who (rightly so) start keeping score at the first of
  * the month and find the first report lacking / broken.
  *
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return AccountCollection
  */
 public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts) : AccountCollection
 {
     $startAmount = '0';
     $endAmount = '0';
     $diff = '0';
     $ids = $accounts->pluck('id')->toArray();
     $yesterday = clone $start;
     $yesterday->subDay();
     $startSet = $this->getSet($ids, $yesterday);
     // get balances for start.
     $backupSet = $this->getSet($ids, $start);
     $endSet = $this->getSet($ids, $end);
     $accounts->each(function (Account $account) use($startSet, $endSet, $backupSet) {
         return self::reportFilter($account, $startSet, $endSet, $backupSet);
     });
     // summarize:
     foreach ($accounts as $account) {
         $startAmount = bcadd($startAmount, $account->startBalance);
         $endAmount = bcadd($endAmount, $account->endBalance);
         $diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance));
     }
     $object = new AccountCollection();
     $object->setStart($startAmount);
     $object->setEnd($endAmount);
     $object->setDifference($diff);
     $object->setAccounts($accounts);
     return $object;
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:43,代码来源:AccountReportHelper.php

示例9: request

 function tour_compare_add()
 {
     $id = request()->input('id');
     if ($id) {
         $query['id'] = $id;
         $query['with_travel_agent'] = true;
         $api_response = json_decode($this->api->get($this->api_url . '/tours?' . http_build_query(array_merge($query, ['access_token' => Session::get('access_token')])))->getBody());
         if ($api_response->data->data[0]) {
             $tour = $api_response->data->data[0];
             $comparison = session()->get('tour_comparison');
             if (!$comparison) {
                 $comparison = new Collection();
             }
             // Check if there's already max amount of comparable tour
             if ($comparison->count() >= 4) {
                 return response()->json(JSend::fail(['comparison' => 'Tidak dapat membandingkan lebih dari 4 paket tour'])->asArray());
             }
             // Make sure no duplicated tour
             if (!$comparison->where('_id', $tour->_id)->count()) {
                 $comparison->push($tour);
             }
             session()->put('tour_comparison', $comparison);
             return response()->json(JSend::success($comparison->toArray())->asArray());
         } else {
             return app::abort(404);
         }
     } else {
         return app()->abort(400);
     }
 }
开发者ID:erickmo,项目名称:capcusv3,代码行数:30,代码来源:APIController.php

示例10: getCategories

 /**
  * @return Collection
  */
 public function getCategories()
 {
     $set = $this->categories->sortByDesc(function (CategoryModel $category) {
         return $category->spent;
     });
     return $set;
 }
开发者ID:ebbz,项目名称:firefly-iii,代码行数:10,代码来源:Category.php

示例11: boot

 /**
  * Bootstrap the application services.
  */
 public function boot()
 {
     parent::boot();
     $this->publishMigrations();
     $app = $this->app;
     if ($app->bound('form')) {
         $app->form->macro('selectCountry', function ($name, $selected = null, $options = []) use($app) {
             $countries = Cache::rememberForever('brianfaust.countries.select.name.cca2', function () {
                 $records = Country::get(['name', 'cca2']);
                 $countries = new Collection();
                 $records->map(function ($item) use(&$countries) {
                     $countries[$item['cca2']] = $item['name']['official'];
                 });
                 return $countries->sort();
             });
             return $app->form->select($name, $countries, $selected, $options);
         });
         $app->form->macro('selectCountryWithId', function ($name, $selected = null, $options = []) use($app) {
             $countries = Cache::rememberForever('brianfaust.countries.select.id.cca2', function () {
                 $records = Country::get(['name', 'id']);
                 $countries = new Collection();
                 $records->map(function ($item) use(&$countries) {
                     $countries[$item['id']] = $item['name']['official'];
                 });
                 return $countries->sort();
             });
             return $app->form->select($name, $countries, $selected, $options);
         });
     }
 }
开发者ID:DraperStudio,项目名称:Laravel-Countries,代码行数:33,代码来源:CountriesServiceProvider.php

示例12: yearInOut

 /**
  * Summarizes all income and expenses, per month, for a given year.
  *
  * @param ReportQueryInterface $query
  * @param                      $year
  * @param bool                 $shared
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function yearInOut(ReportQueryInterface $query, $year, $shared = false)
 {
     // get start and end of year
     $start = new Carbon($year . '-01-01');
     $end = new Carbon($year . '-12-31');
     $shared = $shared == 'shared' ? true : false;
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty('yearInOut');
     $cache->addProperty($year);
     $cache->addProperty($shared);
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $entries = new Collection();
     while ($start < $end) {
         $month = clone $start;
         $month->endOfMonth();
         // total income and total expenses:
         $incomeSum = $query->incomeInPeriodCorrected($start, $month, $shared)->sum('amount_positive');
         $expenseSum = $query->expenseInPeriodCorrected($start, $month, $shared)->sum('amount_positive');
         $entries->push([clone $start, $incomeSum, $expenseSum]);
         $start->addMonth();
     }
     $data = $this->generator->yearInOut($entries);
     $cache->store($data);
     return Response::json($data);
 }
开发者ID:zetaron,项目名称:firefly-iii,代码行数:38,代码来源:ReportController.php

示例13: getExtensions

 /**
  * 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;
 }
开发者ID:notadd,项目名称:framework,代码行数:34,代码来源:ExtensionManager.php

示例14: getExtensions

 /**
  * @return Collection
  */
 public function getExtensions()
 {
     $extensionsDir = $this->getExtensionsDir();
     $dirs = array_diff(scandir($extensionsDir), ['.', '..']);
     $extensions = new Collection();
     $installed = json_decode(file_get_contents(public_path('vendor/composer/installed.json')), true);
     foreach ($dirs as $dir) {
         if (file_exists($manifest = $extensionsDir . '/' . $dir . '/composer.json')) {
             $extension = new Extension($extensionsDir . '/' . $dir, json_decode(file_get_contents($manifest), true));
             if (empty($extension->name)) {
                 continue;
             }
             foreach ($installed as $package) {
                 if ($package['name'] === $extension->name) {
                     $extension->setInstalled(true);
                     $extension->setVersion($package['version']);
                     $extension->setEnabled($this->isEnabled($dir));
                 }
             }
             $extensions->put($dir, $extension);
         }
     }
     return $extensions->sortBy(function ($extension, $name) {
         return $extension->composerJsonAttribute('extra.flarum-extension.title');
     });
 }
开发者ID:RobR8,项目名称:core,代码行数:29,代码来源:ExtensionManager.php

示例15: parseRss

 /**
  * @param string $rss
  * @param int    $limit
  *
  * @return array
  */
 protected function parseRss($rss, $limit = 0)
 {
     // Load the feed
     $feed = simplexml_load_string($rss, 'SimpleXMLElement', LIBXML_NOCDATA);
     // Make limit an integer
     $limit = (int) $limit;
     // Feed could not be loaded
     if ($feed === false) {
         return new Collection();
     }
     $namespaces = $feed->getNamespaces(true);
     // Detect the feed type. RSS 1.0/2.0 and Atom 1.0 are supported.
     $feed = isset($feed->channel) ? $feed->xpath('//item') : $feed->entry;
     $i = 0;
     $items = new Collection();
     foreach ($feed as $item) {
         if ($limit > 0 and $i++ === $limit) {
             break;
         }
         $item_fields = (array) $item;
         // get namespaced tags
         foreach ($namespaces as $ns) {
             $item_fields += (array) $item->children($ns);
         }
         $items->push($item_fields);
     }
     return $items;
 }
开发者ID:KodiComponents,项目名称:module-dashboard,代码行数:34,代码来源:KodiCMSRss.php


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