本文整理汇总了PHP中Illuminate\Support\Collection::all方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::all方法的具体用法?PHP Collection::all怎么用?PHP Collection::all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAllPermissions
/**
* @param GrantableInterface $grantable
*
* @return array
*/
public function getAllPermissions(GrantableInterface $grantable)
{
if (is_null($this->permissions) || $this->permissions->isEmpty()) {
$this->initialize($grantable);
}
$result = $this->permissions->all();
array_filter($result, function ($item) {
return $item;
});
return array_keys($result);
}
示例2: buildSchema
/**
* Generate GraphQL Schema.
*
* @return \GraphQL\Schema
*/
public function buildSchema()
{
// Initialize types
$this->types()->each(function ($type, $key) {
$type = $this->type($key);
if (method_exists($type, 'getInterfaces') && !empty($type->getInterfaces())) {
$this->typesWithInterfaces->push($type);
}
});
$queryFields = $this->queries()->merge($this->connections()->toArray());
$mutationFields = $this->mutations();
$queryType = $this->generateSchemaType($queryFields, 'Query');
$mutationType = $this->generateSchemaType($mutationFields, 'Mutation');
return new Schema(['query' => $queryType, 'mutation' => $mutationType, 'types' => $this->typesWithInterfaces->all()]);
}
示例3: loadItems
/**
* Loads the Eloquent models for the indexed documents found by the search.
* Uses eager loading for the specified relations array.
*
* @param array|null $with
* @return \Elodex\Collection
*/
protected function loadItems(array $with = null)
{
$ids = array_keys($this->documents->all());
$class = $this->entityClass;
// Eager load the index relations by default.
if (is_null($with)) {
$with = (new $class())->getIndexRelations();
}
// Load the Eloquent models from the DB.
$collection = $class::with($with)->find($ids);
// The database query returns the items in a random order which means
// a previously specified sort order in the document search will be lost.
// So we need to manually bring the result in the desired order.
$dictionary = $collection->getDictionary();
$sorted = [];
foreach ($ids as $id) {
$model = $dictionary[$id];
// Fill the model with index metadata.
if (isset($this->metadata[$id]['_score'])) {
$model->setIndexScore($this->metadata[$id]['_score']);
}
if (isset($this->metadata[$id]['_version'])) {
$model->setIndexVersion($this->metadata[$id]['_version']);
}
$sorted[$id] = $model;
}
return new Collection($sorted);
}
示例4: prepareElement
/**
* Mutate an XML element based on the given data.
*
* @param Collection $data
* @param SimpleXMLElement $element
* @param object $object The object.
* @param mixed $providedKey
* @return SimpleXMLElement The new element.
*/
protected function prepareElement(Collection $data, SimpleXMLElement $element, $object, $providedKey = null) : SimpleXMLElement
{
foreach ($data->all() as $value) {
$this->prepareWithReflection($value, $element, $object);
}
return $element;
}
示例5: testBulkOperationException
public function testBulkOperationException()
{
$bulkItems = new Collection([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4]]);
$items = [['create' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 1, 'status' => 409, 'error' => ['type' => 'document_already_exists_exception', 'reason' => '[my_index][1]: document already exists', 'shard' => '1', 'index' => 'my_index']]], ['update' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 2, 'status' => 404, 'error' => ['type' => 'document_missing_exception', 'reason' => '[my_index][2]: document missing', 'shard' => '-1', 'index' => 'my_index']]], ['delete' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 3, 'status' => 404, 'found' => false]], ['index' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 4, 'status' => 200]]];
$e = BulkOperationException::createForResults($items, $bulkItems->all());
$failedItems = $e->getFailedItems();
$failedIds = Arr::pluck($failedItems, 'id');
$this->assertEquals([1, 2], $failedIds);
}
示例6: render
/**
* @return string
*/
public function render()
{
$value = $this->choices->all();
if (!empty($this->label)) {
$label = Element::create('label', $this->label);
$this->nest($label, 'label');
$this->nest('<br>');
}
$this->nest($value, 'choices');
return parent::render();
}
示例7: outputAssets
/**
* Output the collection assets
* @param \Illuminate\Support\Collection $collection
* @param string $type
* @return string
*/
public function outputAssets($collection, $type)
{
if (!$collection->isEmpty()) {
$link = $this->determineLinkingAttribute($type);
$output = array();
foreach ($collection->all() as $name => $attr) {
$output[$name] = $this->createAssetTag($type, $link, $attr);
}
return implode($output, '');
}
}
示例8: buildColumnByCollection
/**
* Transform row column by collection.
*
* @param array $row
* @param \Illuminate\Support\Collection $columns
* @param string $type
* @return array
*/
protected function buildColumnByCollection(array $row, Collection $columns, $type = 'printable')
{
$results = [];
foreach ($columns->all() as $column) {
if ($column[$type]) {
$data = array_get($row, $column['data']);
$results[$column['title']] = $type == 'exportable' ? strip_tags($data) : $data;
}
}
return $results;
}
示例9: run
public function run()
{
if ($this->rules instanceof Collection) {
$this->rules = $this->rules->all();
}
if (is_string($this->rules) && is_subclass_of($this->rules, BaseInterceptor::class)) {
$this->rules = app($this->rules)->apply($this->actor, $this->data, $this->obj);
}
$validator = app('validator')->make($this->data->all(), $this->rules, $this->messages, $this->labels);
if ($validator->fails()) {
abort(400, json_encode($validator->errors()->all()));
}
return $validator;
}
示例10: buildColumnByCollection
/**
* Transform row column by collection.
*
* @param array $row
* @param \Illuminate\Support\Collection $columns
* @param string $type
* @return array
*/
protected function buildColumnByCollection(array $row, Collection $columns, $type = 'printable')
{
$results = [];
foreach ($columns->all() as $column) {
if ($column[$type]) {
$title = $column['title'];
$data = array_get($row, $column['data']);
if ($type == 'exportable') {
$data = $this->decodeContent($data);
$title = $this->decodeContent($title);
}
$results[$title] = $data;
}
}
return $results;
}
示例11: applyTransform
public function applyTransform()
{
$transforms = $this->transforms->all();
$datas = empty($this->inputDatas) ? [] : $this->inputDatas;
if (empty($transforms) || empty($datas)) {
$this->results = $datas;
return $this;
}
$tmp = [];
foreach ($transforms as $transform) {
$tmp = Transform::make($transform, $datas);
}
$this->hasTransForm = TRUE;
$this->results = new Collection($tmp);
return $this;
}
示例12: go
/**
* Go
*
* Goes through all of the registered modules and attempts
* to activate them. Performs checks to ensure that modules
* that declare dependencies that have not been satisfied
* will not be activated.
*
* Registers any directories with the class loader
*
* @return void
*/
public function go()
{
$this->handlePreRegistered();
$toActivate = $this->registeredModules->all();
// This 'while' loop runs continuously allowing for modules
// to be checked multiple times which allows for dependencies.
while (count($toActivate) > 0) {
foreach ($toActivate as $name => $module) {
$canActivate = true;
$dependencies = $module->dependencies();
// If we've got dependencies, check them all to make sure all have been activated
// before activating this particular module.
if (!empty($dependencies)) {
foreach ($dependencies as $dependency) {
// First off, if this dependency hasn't even been register, we can never
// activate this module, so let's skip it and not try again.
if (!$this->registeredModules->has($dependency)) {
$canActivate = false;
$this->dispatcher->fire(self::EVENT_ACTIVATION_FAILED . ' ' . $name, $module);
unset($toActivate[$name]);
continue;
}
// At this point, the dependency has been registered but not activated,
// so let's skip this module and come back to it.
if (!$this->activeModules->has($dependency)) {
$canActivate = false;
}
}
}
// Now let's activate this sucka! Also, we remove it from the list
// so we don't try to activate it again.
if ($canActivate) {
$this->activeModules->put($name, $module->activate());
$this->dispatcher->fire(self::EVENT_ACTIVE . " {$name}", $module);
unset($toActivate[$name]);
}
}
}
$this->classLoader->register();
}
示例13: handleiSortCol_0
/**
* @param $value
*/
protected function handleiSortCol_0($value)
{
if (Input::get('sSortDir_0') == 'desc') {
$direction[$value] = BaseEngine::ORDER_DESC;
} else {
$direction[$value] = BaseEngine::ORDER_ASC;
}
$columns = array();
//check if order is allowed
if (empty($this->orderColumns)) {
$columns[] = array(0 => $value, 1 => $this->getNameByIndex($value));
$this->order($columns, $direction);
return;
}
//prepare order array
$cleanNames = array();
foreach ($this->orderColumns as $c) {
if (strpos($c, ':') !== FALSE) {
$cleanNames[] = substr($c, 0, strpos($c, ':'));
} else {
$cleanNames[] = $c;
}
}
$iSortingCols = Input::get('iSortingCols');
$sortingCols[] = $value;
for ($i = 1; $i < $iSortingCols; $i++) {
$isc = Input::get('iSortCol_' . $i);
$sortingCols[] = $isc;
$direction[$isc] = Input::get('sSortDir_' . $i);
}
$allColumns = array_keys($this->columns->all());
foreach ($sortingCols as $num) {
if (isset($allColumns[$num]) && in_array($allColumns[$num], $cleanNames)) {
$columns[] = array(0 => $num, 1 => $this->orderColumns[array_search($allColumns[$num], $cleanNames)]);
}
}
$this->order($columns, $direction);
return;
}
示例14: getAllAttributes
/**
* @return Collection
*/
public function getAllAttributes()
{
$all = new Collection();
foreach ($this->attributes as $attr) {
$all->put($attr->name, $attr);
}
foreach ($this->sections->all() as $section) {
foreach ($section->getAttributes() as $attr) {
$all->put($attr->name, $attr);
}
}
foreach ($this->tabs->all() as $tab) {
foreach ($tab->getAttributes() as $attr) {
$all->put($attr->name, $attr);
}
foreach ($tab->getSections() as $section) {
foreach ($section as $attr) {
$all->put($attr->name, $attr);
}
}
}
return $all;
}
示例15: getSheetArrayFromAnyKindOfCollection
/**
* Takes any kind of collection returned by Maatwebsite\Excel and turns it
* into an array of RowCollections.
*
* This is needed because the library returns a SheetCollection if there are
* multiple sheets and a RowCollection if there is only one.
*
* @see http://www.maatwebsite.nl/laravel-excel/docs/import#results
* @param mixed $collection A RowCollection or SheetCollection.
* @result \Maatwebsite\Excel\Collections\RowCollection[]
*/
protected function getSheetArrayFromAnyKindOfCollection(Collection $collection)
{
if ($collection instanceof RowCollection) {
$sheets = [$collection];
} elseif ($collection instanceof SheetCollection) {
$sheets = $collection->all();
} else {
throw new Exception('Unknown class returned from Excel: ' . get_class($collection));
}
return $sheets;
}