當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::map方法代碼示例

本文整理匯總了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]);
 }
開發者ID:lukebro,項目名稱:flash,代碼行數:12,代碼來源:FlashFactory.php

示例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);
 }
開發者ID:benconstable,項目名稱:laravel-localize-middleware,代碼行數:14,代碼來源:Stack.php

示例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());
 }
開發者ID:hughgrigg,項目名稱:ching-shop,代碼行數:17,代碼來源:OfferSet.php

示例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();
 }
開發者ID:hughgrigg,項目名稱:ching-shop,代碼行數:13,代碼來源:PotentialOffer.php

示例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);
 }
開發者ID:mpociot,項目名稱:laravel-apidoc-generator,代碼行數:11,代碼來源:CollectionWriter.php

示例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);
 }
開發者ID:charles-wc,項目名稱:assets-manager,代碼行數:17,代碼來源:Asset.php

示例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);
 }
開發者ID:spatie,項目名稱:laravel-slack-slash-command,代碼行數:7,代碼來源:CatchAll.php

示例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;
    }
開發者ID:npmweb,項目名稱:service-opportunities,代碼行數:28,代碼來源:CyoRegistrationDataSource.php

示例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);
 }
開發者ID:morilog,項目名稱:acl,代碼行數:11,代碼來源:Role.php

示例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('');
 }
開發者ID:SkysoulDesign,項目名稱:TempArk,代碼行數:37,代碼來源:FormBuilder.php

示例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;
     });
 }
開發者ID:MehmetNuri,項目名稱:faveo-helpdesk,代碼行數:27,代碼來源:CollectionEngine.php

示例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);
 }
開發者ID:morilog,項目名稱:acl,代碼行數:12,代碼來源:User.php

示例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();
 }
開發者ID:a161527,項目名稱:cs319-p2t5,代碼行數:12,代碼來源:Payload.php

示例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);
 }
開發者ID:shen0100,項目名稱:blueprint,代碼行數:33,代碼來源:Blueprint.php

示例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;
 }
開發者ID:filmoteca,項目名稱:filmoteca,代碼行數:11,代碼來源:FilmTransformer.php


注:本文中的Illuminate\Support\Collection::map方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。