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


PHP Collection::contains方法代码示例

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


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

示例1: withImages

 /**
  * @return $this
  */
 public function withImages()
 {
     if (!$this->extended->contains("images")) {
         return $this->extend('images');
     }
     return $this;
 }
开发者ID:kduma-archive,项目名称:trakt-api-wrapper,代码行数:10,代码来源:Endpoint.php

示例2: contains

 /**
  * Determine if a key exists in the collection.
  *
  * @param  mixed  $key
  * @param  mixed  $value
  * @return bool
  */
 public function contains($key, $value = null)
 {
     if (func_num_args() == 1) {
         return !is_null($this->find($key));
     }
     return parent::contains($key, $value);
 }
开发者ID:eunicon,项目名称:meetup,代码行数:14,代码来源:Collection.php

示例3: generate

 /**
  * Generate documentation with the name and version.
  *
  * @param string $name
  * @param string $version
  *
  * @return bool
  */
 public function generate(Collection $controllers, $name, $version)
 {
     $resources = $controllers->map(function ($controller) use($version) {
         $controller = $controller instanceof ReflectionClass ? $controller : new ReflectionClass($controller);
         $actions = new Collection();
         // Spin through all the methods on the controller and compare the version
         // annotation (if supplied) with the version given for the generation.
         // We'll also build up an array of actions on each resource.
         foreach ($controller->getMethods() as $method) {
             if ($versionAnnotation = $this->reader->getMethodAnnotation($method, Annotation\Versions::class)) {
                 if (!in_array($version, $versionAnnotation->value)) {
                     continue;
                 }
             }
             if ($annotations = $this->reader->getMethodAnnotations($method)) {
                 if (!$actions->contains($method)) {
                     $actions->push(new Action($method, new Collection($annotations)));
                 }
             }
         }
         $annotations = new Collection($this->reader->getClassAnnotations($controller));
         return new Resource($controller->getName(), $controller, $annotations, $actions);
     });
     return $this->generateContentsFromResources($resources, $name);
 }
开发者ID:shen0100,项目名称:blueprint,代码行数:33,代码来源:Blueprint.php

示例4: addItem

 /**
  * @param Buyable $item
  * @param int $amount
  * @return $this
  */
 public function addItem(Buyable $item, $amount = 1)
 {
     //注意此处$value传入引用, 导致filter()返回值是已被修改过amount的.
     //然而, 由于filter在对数组$this->_items进行foreach操作的时候
     //$key和$value都是传值, 所以$this->_items并不会被改变.
     //可以通过修改filter函数来达到目的, 但这样并不是很elegant的做法
     //这里通过获取到$key值,来做到在原数组中手动去修改.
     $has_same_items = $this->_items->contains(function ($key, $value) use($item, $amount) {
         if ($value['buyable']['id'] == $item->getIdentifer()) {
             $this->addExistsIntoItems($key, $amount, $item);
             return true;
         }
     });
     if (!$has_same_items) {
         $this->addNewIntoItems($item, $amount);
     }
     return $this;
 }
开发者ID:whplay,项目名称:ohmate-shop,代码行数:23,代码来源:SessionDrivenCart.php

示例5: getAncestors

 /**
  * Recursively build collection of ancestor category IDs.
  *
  * @return \Illuminate\Support\Collection
  */
 public function getAncestors()
 {
     $ancestors = new Collection();
     $ancestor = $this;
     while (($ancestor = $ancestor->parent) && !$ancestors->contains($ancestor)) {
         $ancestors->push($ancestor);
         break;
     }
     return $ancestors;
 }
开发者ID:kolexndr,项目名称:mustard,代码行数:15,代码来源:Category.php

示例6: handleAlteredFile

 protected function handleAlteredFile($file_path)
 {
     if ($this->baseline->contains($file_path) && ($this->baseline[$file_path]['hash'] != $this->current[$file_path]['hash'] || $this->baseline[$file_path]['last_modified'] != $this->current[$file_path]['last_modified'])) {
         $this->altered->put($file_path, $this->current[$file_path]);
         //-- add the baseline_hash
         $this->altered[$file_path]['baseline_hash'] = $this->baseline[$file_path]['hash'];
         //-- update altered file in baseline table
         BaselineFile::updateFromFile($this->current[$file_path], $this->account);
         $this->saveAlteredFileToHistory($file_path);
     }
 }
开发者ID:joshwhatk,项目名称:super-scan,代码行数:11,代码来源:Scan.php

示例7: contains

 /**
  * Determine if a key exists in the collection.
  *
  * @param  mixed  $key
  * @param  mixed  $value
  * @return bool
  */
 public function contains($key, $value = null)
 {
     if (func_num_args() == 1 && !$key instanceof Closure) {
         $key = $key instanceof Model ? $key->getKey() : $key;
         return $this->filter(function ($m) use($key) {
             return $m->getKey() === $key;
         })->count() > 0;
     } elseif (func_num_args() == 2) {
         return $this->where($key, $value)->count() > 0;
     }
     return parent::contains($key);
 }
开发者ID:HarveyCheng,项目名称:myblog,代码行数:19,代码来源:Collection.php

示例8: contains

 /**
  * Determine if a key exists in the collection.
  *
  * @param  mixed  $key
  * @param  mixed  $value
  * @return bool
  */
 public function contains($key, $value = null)
 {
     if (func_num_args() == 2) {
         return parent::contains($key, $value);
     }
     if ($this->useAsCallable($key)) {
         return parent::contains($key);
     }
     $key = $key instanceof Model ? $key->getKey() : $key;
     return parent::contains(function ($k, $m) use($key) {
         return $m->getKey() == $key;
     });
 }
开发者ID:mubassirhayat,项目名称:Laravel51-starter,代码行数:20,代码来源:Collection.php

示例9: getControllers

 /**
  * Get all the controller instances.
  *
  * @return array
  */
 protected function getControllers()
 {
     $controllers = new Collection();
     foreach ($this->router->getRoutes() as $collections) {
         foreach ($collections as $route) {
             if ($controller = $route->getController()) {
                 if (!$controllers->contains($controller)) {
                     $controllers->push($controller);
                 }
             }
         }
     }
     return $controllers;
 }
开发者ID:riclt,项目名称:api,代码行数:19,代码来源:Docs.php

示例10: createMissingBooks

 protected function createMissingBooks(Author $author, Collection $authorData, Collection $existingBooks)
 {
     $missingBooks = [];
     debug('Creating missing books', $authorData);
     foreach ($authorData as $googleBookId => $book) {
         if ($existingBooks->contains('google_books_id', $googleBookId)) {
             continue;
         }
         $newBook = $this->addBook($book, $googleBookId);
         foreach ($book['authors'] as $authorName) {
             if ($authorName != $author->name) {
                 $author = Author::firstOrCreate(['name' => $authorName]);
             }
             $newBook->authors()->create(['author_id' => $author->id, 'book_id' => $newBook->id]);
         }
         $missingBooks[] = $newBook;
     }
     return $missingBooks;
 }
开发者ID:ScottBurfieldMills,项目名称:BookFeed,代码行数:19,代码来源:AuthorService.php

示例11: getDiffFiles

 function getDiffFiles(array $files, \Illuminate\Support\Collection $seeded, \LaravelSeed\Contracts\ProviderInterface $provider)
 {
     $edited = [];
     array_map(function ($seed) use($files, &$edited, $provider) {
         $fullPath = getFullPathSource($seed->name, $provider);
         if (!in_array($fullPath, $files)) {
             return false;
         }
         $key = array_search($fullPath, $files);
         $filemtime = filemtime($files[$key]);
         if ($filemtime > $seed->hash) {
             $edited[] = $fullPath;
         }
         return false;
     }, $seeded->toArray());
     $diff = [];
     array_walk($files, function ($file) use($seeded, &$diff) {
         $filename = pathinfo($file)['filename'];
         if (!$seeded->contains('name', $filename)) {
             $diff[] = $file;
         }
     });
     return array_merge($diff, $edited);
 }
开发者ID:parfumix,项目名称:laravel-smart-seed,代码行数:24,代码来源:Helpers.php

示例12: contains

 public function contains($key)
 {
     return $this->data->contains($key);
 }
开发者ID:portonefive,项目名称:essentials,代码行数:4,代码来源:Dictionary.php

示例13: getNumProtected

 public function getNumProtected($projectUuid)
 {
     $packages = new Collection();
     if (!strpos($projectUuid, '+')) {
         // collect packages shared with a single project
         //
         $packageVersionSharings = PackageVersionSharing::where('project_uuid', '=', $projectUuid)->get();
         for ($i = 0; $i < sizeof($packageVersionSharings); $i++) {
             $packageVersion = PackageVersion::where('package_version_uuid', '=', $packageVersionSharings[$i]->package_version_uuid)->first();
             $package = Package::where('package_uuid', '=', $packageVersion->package_uuid)->first();
             if ($package && !$packages->contains($package)) {
                 $packages->push($package);
                 // add to packages query
                 //
                 if (!isset($packagesQuery)) {
                     $packagesQuery = Package::where('package_uuid', '=', $package->package_uuid);
                 } else {
                     $packagesQuery = $packagesQuery->orWhere('package_uuid', '=', $package->package_uuid);
                 }
                 // add filters
                 //
                 $packagesQuery = PackageTypeFilter::apply($packagesQuery);
                 $packagesQuery = DateFilter::apply($packagesQuery);
                 $packagesQuery = LimitFilter::apply($packagesQuery);
             }
         }
     } else {
         // collect packages shared with multiple projects
         //
         $projectUuids = explode('+', $projectUuid);
         foreach ($projectUuids as $projectUuid) {
             $packageVersionSharings = PackageVersionSharing::where('project_uuid', '=', $projectUuid)->get();
             for ($i = 0; $i < sizeof($packageVersionSharings); $i++) {
                 $packageVersion = PackageVersion::where('package_version_uuid', '=', $packageVersionSharings[$i]->package_version_uuid)->first();
                 $package = Package::where('package_uuid', '=', $packageVersion->package_uuid)->first();
                 if ($package && !$packages->contains($package)) {
                     $packages->push($package);
                     // add to packages query
                     //
                     if (!isset($packagesQuery)) {
                         $packagesQuery = Package::where('package_uuid', '=', $package->package_uuid);
                     } else {
                         $packagesQuery = $packagesQuery->orWhere('package_uuid', '=', $package->package_uuid);
                     }
                     // add filters
                     //
                     $packagesQuery = PackageTypeFilter::apply($packagesQuery);
                     $packagesQuery = DateFilter::apply($packagesQuery);
                     $packagesQuery = LimitFilter::apply($packagesQuery);
                 }
             }
         }
     }
     // perform query
     //
     if (isset($packagesQuery)) {
         return $packagesQuery->count();
     } else {
         return 0;
     }
 }
开发者ID:pombredanne,项目名称:open-swamp,代码行数:61,代码来源:PackagesController.php

示例14: sortMiddleware

 /**
  * Sort the given middleware by priority.
  *
  * @param  \Illuminate\Support\Collection  $middlewares
  * @return \Illuminate\Support\Collection
  */
 protected function sortMiddleware(Collection $middlewares)
 {
     $priority = collect($this->middlewarePriority);
     $sorted = collect();
     foreach ($middlewares as $middleware) {
         if ($sorted->contains($middleware)) {
             continue;
         }
         if (($index = $priority->search($middleware)) !== false) {
             $sorted = $sorted->merge($priority->take($index)->filter(function ($middleware) use($middlewares, $sorted) {
                 return $middlewares->contains($middleware) && !$sorted->contains($middleware);
             }));
         }
         $sorted[] = $middleware;
     }
     return $sorted;
 }
开发者ID:davidhemphill,项目名称:framework,代码行数:23,代码来源:Router.php

示例15: getMatchedAbilityId

 /**
  * Get the ID of the ability that matches one of the applicable abilities.
  *
  * @param  \Illuminate\Support\Collection  $abilityMap
  * @param  \Illuminate\Support\Collection  $applicable
  * @return int|null
  */
 protected function getMatchedAbilityId(Collection $abilityMap, Collection $applicable)
 {
     foreach ($abilityMap as $id => $identifier) {
         if ($applicable->contains($identifier)) {
             return $id;
         }
     }
 }
开发者ID:JosephSilber,项目名称:bouncer,代码行数:15,代码来源:Clipboard.php


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