本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
});
}
示例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;
}
示例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;
}
示例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);
}
示例12: contains
public function contains($key)
{
return $this->data->contains($key);
}
示例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;
}
}
示例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;
}
示例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;
}
}
}