/** * 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]); }
/** * 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); }
/** * 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()); }
/** * @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(); }
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); }
/** * 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); }
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); }
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; }
/** * @param Collection $permissions * @return mixed */ public function addPermissions(Collection $permissions) { $permissionIds = $permissions->map(function ($perm) { return $perm->getId(); })->toArray(); return $this->permissions()->sync($permissionIds); }
/** * 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(''); }
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; }); }
/** * @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); }
/** * Get the array of claims. * * @return array */ public function toArray() { $collection = $this->claims->map(function (Claim $claim) { return $claim->getValue(); }); return $collection->toArray(); }
/** * 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); }
/** * @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; }
/** * @param Collection $collection * @return \Illuminate\Support\Collection */ public function collection(Collection $collection) { $activities = $collection->map(function ($item) { return self::single(Collection::make($item)); }); return $activities; }
public static function createData(Collection $rawCollection) { $datamodels = $rawCollection->map(function ($item, $key) { return new static($item); })->flatten(); return $datamodels; }
protected function displayOverview(Collection $backupDestinationStatuses) { $headers = ['Name', 'Disk', 'Reachable', 'Healthy', '# of backups', 'Newest backup', 'Used storage']; $rows = $backupDestinationStatuses->map(function (BackupDestinationStatus $backupDestinationStatus) { return $this->convertToRow($backupDestinationStatus); }); $this->table($headers, $rows); }
/** * Determine if two given recipient lists match. * * @param \Illuminate\Support\Collection $expected * @param \Illuminate\Support\Collection $recipients * @return bool */ protected function recipientsMatch($expected, $recipients) { $expected = $expected->map(function ($expected) { return is_object($expected) ? $expected->email : $expected; }); return $recipients->map(function ($recipient) { return is_object($recipient) ? $recipient->email : $recipient; })->diff($expected)->count() === 0; }
/** * ContestantNotFoundException constructor. * * @param null $message * @param int $code * @param \Exception|null $previous * @param Collection|null $availableContestants */ public function __construct($message = null, $code = 0, \Exception $previous = null, Collection $availableContestants = null) { if ($availableContestants !== null) { $availableContestantNames = $availableContestants->map(function (Contestant $contestant) { return $contestant->getName(); }); $message .= PHP_EOL . 'Available contestants: ' . implode(', ', $availableContestantNames->toArray()); } parent::__construct($message, $code, $previous); }
public function getCreatorsForVideos(Collection $videos, $force = false) { $creators = collect([]); $videos->map(function ($video) { return $video->channel_id; })->unique()->each(function ($item) use(&$creators, $force) { $creators = $this->getCreator($item, $force)->merge($creators->all()); }); return $creators; }
/** * Dumps the databases to the given directory. * Returns an array with paths to the dump files. * * @param string $directory * * @return array */ protected function dumpDatabases(string $directory) : array { return $this->dbDumpers->map(function (DbDumper $dbDumper) use($directory) { consoleOutput()->info("Dumping database {$dbDumper->getDbName()}..."); $fileName = $dbDumper->getDbName() . '.sql'; $temporaryFile = $directory . '/' . $fileName; $dbDumper->dumpToFile($temporaryFile); return $temporaryFile; })->toArray(); }
protected function getPayload() : array { $payload = ['text' => $this->text, 'channel' => $this->channel, 'link_names' => true, 'unfurl_links' => true, 'unfurl_media' => true, 'mrkdwn' => true, 'response_type' => $this->responseType, 'attachments' => $this->attachments->map(function (Attachment $attachment) { return $attachment->toArray(); })->toArray()]; if (!empty($this->icon)) { $payload[$this->getIconType()] = $this->icon; } return $payload; }
/** * Creates inexistant organisations. * * @param \Illuminate\Support\Collection $all * @param \Illuminate\Support\Collection $existing * * @return \Illuminate\Support\Collection */ protected function create(Collection $all, Collection $existing) { return $all->map(function ($organisation) use($existing) { $existing = $existing->where('id', $organisation->id)->first(); if ($existing !== null) { $organisation = $existing->fill(['name' => $organisation->name]); } $organisation->save(); return $organisation; }); }
/** * Build the grid rows. * * @param array $data * * @return void */ protected function buildRows(array $data) { $this->rows = collect($data)->map(function ($val, $key) { $row = new Row($key, $val); $row->setKeyName($this->keyName); $row->setPath($this->resource()); return $row; }); if ($this->rowsCallback) { $this->rows->map($this->rowsCallback); } }
/** * @param \Illuminate\Support\Collection $results * @return array */ protected function totals($results) { $return = new Collection(); $results->map(function ($results, $provider) use($return) { $totals = new Collection(); foreach ($results as $scope => $resultSet) { $totals[$scope] = array_sum(array_values($resultSet)); } $totals['_total'] = array_sum($totals->toArray()); $return[$provider] = $totals; }); return $return; }
/** * Update salts in the environment file. * * @param bool $force Whether or not to force update any existing values * * @return Collection */ protected function update_salts($force = false) { return $this->salts->map(function ($salt) use($force) { list($key, $value) = $salt; if (!$force && $this->env->hasKey($key)) { WP_CLI::line("The '{$key}' already exists, skipping."); $salt['skipped'] = true; return $salt; } $this->env->set($key, $value, "'"); return $salt; }); }
public function getVideosForPlaylists(Collection $playlists, $force = false) { if ($playlists->isEmpty()) { return $playlists; } $videos = collect([]); $playlists->map(function ($item) { return $item->id; })->unique()->each(function ($item) use(&$videos, $force) { $videos = $this->getVideosInPlaylist($item, $force)->merge($videos->all()); }); return $videos; }
public function test_it_can_resolve_buzzes() { $contestants = new Collection([new Contestant("Phil"), new Contestant("Bob")]); $categories = []; $board = new Board($contestants, $categories, new Resolver(), new BuzzerStatus(), new FinalJeopardy\State(new FinalJeopardyClue("mock_category", "mock_clue", "mock_answer"), $contestants->map(function (Contestant $contestant) { return $contestant->getName(); })->toArray())); $board->getResolver()->addBuzz(new BuzzReceivedEvent(new Contestant("Phil"), 90)); $board->getResolver()->addBuzz(new BuzzReceivedEvent(new Contestant("Phil"), 50)); $board->getResolver()->addBuzz(new BuzzReceivedEvent(new Contestant("Bob"), 70)); $resolution = $board->resolveBuzzes(); $this->assertEquals(50, $resolution->getTime()); $this->assertEquals("Phil", $resolution->getContestant()->getName()); }
/** * * 集合元素 转换成 字符串 * * implode * */ public function implode() { $val = $this->collection->map(function ($val, $key) { return $val['price']; }); debug($val); //Desk,Chair,Bookcase,Door $implode = $this->collection->implode('product', ','); debug($implode); //1-2-3-4-5 $implode = collect([1, 2, 3, 4, 5])->implode('-'); debug($implode); return view('index'); }