本文整理匯總了PHP中Illuminate\Support\Collection::map方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::map方法的具體用法?PHP Collection::map怎麽用?PHP Collection::map使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::map方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: again
/**
* Reflash message to next session.
*
* @return void
*/
public function again()
{
$this->next = $this->current->map(function ($item) {
return $item->toArray();
})->merge($this->next)->toArray();
$this->session->keep([$this->key]);
}
示例2: determineLocale
/**
* Determine the locale from the underlying determiner stack.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
public function determineLocale(Request $request)
{
return $this->determiners->map(function ($determiner) use($request) {
return $determiner->determineLocale($request);
})->first(function ($index, $locale) {
return $locale !== null;
}, $this->fallback);
}
示例3: potentials
/**
* Buckets for each potential offer, keeping duplicate offers.
*
* @throws \InvalidArgumentException
*
* @return Collection|PotentialOffer[]
*/
private function potentials() : Collection
{
return $this->components->map(function (OfferComponent $component) {
return $component->product();
})->filter(function (Product $product) {
return $product->offers->count();
})->reduce(function (Collection $potentials, Product $product) {
return $potentials->push(new PotentialOffer($product->offers->first()));
}, new Collection());
}
示例4: listComponents
/**
* @return string
*/
public function listComponents() : string
{
$identifiers = $this->components->map(function (OfferComponent $component) {
return $component->product()->sku;
});
if ($identifiers->count() > 1) {
return sprintf('%s and %s', $identifiers->slice(0, -1)->implode(', '), $identifiers->last());
}
return $identifiers->pop();
}
示例5: getCollection
public function getCollection()
{
$collection = ['variables' => [], 'info' => ['name' => '', '_postman_id' => Uuid::uuid4()->toString(), 'description' => '', 'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json'], 'item' => $this->routeGroups->map(function ($routes, $groupName) {
return ['name' => $groupName, 'description' => '', 'item' => $routes->map(function ($route) {
return ['name' => $route['title'] != '' ? $route['title'] : url($route['uri']), 'request' => ['url' => url($route['uri']), 'method' => $route['methods'][0], 'body' => ['mode' => 'formdata', 'formdata' => collect($route['parameters'])->map(function ($parameter, $key) {
return ['key' => $key, 'value' => isset($parameter['value']) ? $parameter['value'] : '', 'type' => 'text', 'enabled' => true];
})->values()->toArray()], 'description' => $route['description'], 'response' => []]];
})->toArray()];
})->values()->toArray()];
return json_encode($collection);
}
示例6: display
/**
* Get the assets in a display
* @return string
*/
public function display()
{
// get the path and format
$format = $this->getFormat();
$path = $this->getPath();
// map the assets into a new collection called $tags
$tags = $this->_assets->map(function ($asset) use($format, $path) {
// build the asset path, sprintf it
$asset_path = $path . '/' . $asset;
return sprintf($format, $asset_path);
});
return $tags->implode(PHP_EOL);
}
示例7: getCommandListAttachment
protected function getCommandListAttachment(Collection $handlers) : Attachment
{
$attachmentFields = $handlers->map(function (SignatureHandler $handler) {
return AttachmentField::create($handler->getFullCommand(), $handler->getDescription());
})->all();
return Attachment::create()->setColor('warning')->setTitle('Did you mean:')->setFields($attachmentFields);
}
示例8: getQuery
public function getQuery()
{
// get all child orgs
if ($this->orgUid) {
$selectedOrgs = new Collection($this->organization->find($this->orgUid)->thisAndAllDescendentOrganizations());
$uids = $selectedOrgs->map(function ($org) {
return $org->uid;
})->all();
// have to do the IN clause by hand; Laravel doesn't support
$inList = '(' . implode(',', array_map(function ($uid) {
return '"' . $uid . '"';
}, $uids)) . ')';
} else {
$inList = '("foo")';
// not used, just avoid syntax error
}
// get query
return <<<EOQ
SELECT r.uid AS 'registration_uid', org.name AS 'organization', r.first_name,
r.last_name, r.start_date, r.description, r.num_participants, r.num_hours,
r.num_participants * r.num_hours AS 'total_hours', r.address1, r.address2,
r.city, r.state, r.postal_code, r.country, r.phone, r.email, r.created_at
FROM cyo_project_registrations r
JOIN organizations org ON org.id = r.organization_id
WHERE (? IS NULL) OR (org.uid IN {$inList})
ORDER BY r.created_at ASC
EOQ;
}
示例9: addPermissions
/**
* @param Collection $permissions
* @return mixed
*/
public function addPermissions(Collection $permissions)
{
$permissionIds = $permissions->map(function ($perm) {
return $perm->getId();
})->toArray();
return $this->permissions()->sync($permissionIds);
}
示例10: generateForm
/**
* Compile the final form
*
* @return string
*/
protected function generateForm()
{
$form = $this->generateTag($this->form->pull(0));
/**
* Remove Empty Items
*/
$this->form = $this->form->reject(function ($obj) {
return $obj instanceof Collection ? $obj->isEmpty() : false;
});
return $this->form->map(function ($item) {
/**
* Remove ErrorBox if there is no error
*/
if ($item instanceof Collection && $item->get('element') == 'errorMessage' && $item->get('errors') === null) {
return false;
}
/**
* Generate tag if $item is not empty
*/
if ($item instanceof Collection) {
/**
* Detect Errors
*/
$error = $this->appendErrors($item);
return $this->wrap($item, $error);
}
/**
* Return item if it`s just an string
*/
return $item;
})->prepend($form)->implode('');
}
示例11: compileArray
private function compileArray($columns)
{
$self = $this;
$this->workingCollection = $this->collection->map(function ($row) use($columns, $self) {
$entry = array();
// add class and id if needed
if (!is_null($self->getRowClass()) && is_callable($self->getRowClass())) {
$entry['DT_RowClass'] = call_user_func($self->getRowClass(), $row);
}
if (!is_null($self->getRowId()) && is_callable($self->getRowId())) {
$entry['DT_RowId'] = call_user_func($self->getRowId(), $row);
}
if (!is_null($self->getRowData()) && is_callable($self->getRowData())) {
$entry['DT_RowData'] = call_user_func($self->getRowData(), $row);
}
$i = 0;
foreach ($columns as $col) {
if ($self->getAliasMapping()) {
$entry[$col->getName()] = $col->run($row);
} else {
$entry[$i] = $col->run($row);
}
$i++;
}
return $entry;
});
}
示例12: addRoles
/**
* @param Collection $roles
* @param bool $detaching
* @return mixed
*/
public function addRoles(Collection $roles, $detaching = true)
{
$roleIds = $roles->map(function ($role) {
return $role->getId();
})->toArray();
return $this->roles()->sync($roleIds, $detaching);
}
示例13: toArray
/**
* Get the array of claims.
*
* @return array
*/
public function toArray()
{
$collection = $this->claims->map(function (Claim $claim) {
return $claim->getValue();
});
return $collection->toArray();
}
示例14: 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);
}
示例15: 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;
}