当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::transform方法代码示例

本文整理汇总了PHP中Illuminate\Support\Collection::transform方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::transform方法的具体用法?PHP Collection::transform怎么用?PHP Collection::transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Collection的用法示例。


在下文中一共展示了Collection::transform方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fill

 /**
  * @param array|Arrayable $data
  * @return $this
  */
 public function fill($data)
 {
     $this->data = new Collection($data);
     $this->data->transform(function ($record) {
         return $record instanceof Arrayable ? $record->toArray() : $record;
     });
     return $this;
 }
开发者ID:cocona,项目名称:core,代码行数:12,代码来源:Overview.php

示例2: getFields

 /**
  * Get the fields of the type.
  *
  * @return array
  */
 public function getFields()
 {
     $collection = new Collection($this->fields());
     return $collection->transform(function ($field, $name) {
         if (is_string($field)) {
             $field = app($field);
             $field->name = $name;
             return $field->toArray();
         } else {
             $resolver = $this->getFieldResolver($name, $field);
             if ($resolver) {
                 $field['resolve'] = $resolver;
             }
             return $field;
         }
     })->toArray();
 }
开发者ID:nuwave,项目名称:laravel-graphql-relay,代码行数:22,代码来源:GraphQLType.php

示例3: testTransform

 public function testTransform()
 {
     $data = new Collection(['first' => 'taylor', 'last' => 'otwell']);
     $data->transform(function ($item, $key) {
         return $key . '-' . strrev($item);
     });
     $this->assertEquals(['first' => 'first-rolyat', 'last' => 'last-llewto'], $data->all());
 }
开发者ID:sa7bi,项目名称:euro16,代码行数:8,代码来源:SupportCollectionTest.php

示例4: formatData

 /**
  * @param Collection $data
  * @return mixed
  */
 private function formatData(Collection $data)
 {
     return $data->transform(function ($item) {
         return $this->data_provider->transform($item);
     });
 }
开发者ID:xxxcoltxxx,项目名称:grid-laravel,代码行数:10,代码来源:GridTable.php

示例5: generateSuffix

 /**
  * Generate a unique suffix for the given slug (and list of existing, "similar" slugs.
  *
  * @param string $slug
  * @param string $separator
  * @param \Illuminate\Support\Collection $list
  * @return string
  */
 protected function generateSuffix($slug, $separator, Collection $list)
 {
     $len = strlen($slug . $separator);
     // If the slug already exists, but belongs to
     // our model, return the current suffix.
     if ($list->search($slug) === $this->model->getKey()) {
         $suffix = explode($separator, $slug);
         return end($suffix);
     }
     $list->transform(function ($value, $key) use($len) {
         return intval(substr($value, $len));
     });
     // find the highest value and return one greater.
     return $list->max() + 1;
 }
开发者ID:cviebrock,项目名称:eloquent-sluggable,代码行数:23,代码来源:SlugService.php

示例6: transformAnnotationAddon

 protected function transformAnnotationAddon(Collection $collection)
 {
     return $collection->transform(function ($item, $class) {
         return "{$item['name']}({$class}::class)";
     })->implode("\n");
 }
开发者ID:codexproject,项目名称:core,代码行数:6,代码来源:CodexCollector.php

示例7: generateType

 /**
  * Generate type from collection of fields.
  *
  * @param  Collection $fields
  * @param  array     $options
  * @return \GraphQL\Type\Definition\ObjectType
  */
 public function generateType(Collection $fields, $options = [])
 {
     $typeFields = $fields->transform(function ($field) {
         if (is_string($field)) {
             return app($field)->toArray();
         }
         return $field;
     })->toArray();
     return new ObjectType(array_merge(['fields' => $typeFields], $options));
 }
开发者ID:nuwave,项目名称:laravel-graphql-relay,代码行数:17,代码来源:GraphQL.php

示例8: createTags

 /**
  * Create new tags from a string "group:tag_name" and fetch tag from a tag id.
  *
  * @param array $tags
  * @param bool  $isAdmin
  *
  * @return Collection
  */
 protected function createTags(array $tags, $isAdmin = false)
 {
     $newTags = new Collection($tags);
     // Transform the user input tags into tag objects
     $newTags->transform(function ($tagNameOrId) use($isAdmin) {
         if (strpos($tagNameOrId, ':') !== false && $isAdmin) {
             return (new Tag())->createTagFromString($tagNameOrId);
         } else {
             return Tag::find($tagNameOrId);
         }
     });
     // Filter out invalid tags entered by the user
     $newTags = $newTags->filter(function ($tag) {
         return $tag instanceof Tag;
     });
     return $newTags;
 }
开发者ID:oliverpool,项目名称:tinyissue,代码行数:25,代码来源:CrudTagTrait.php

示例9: createImageDerivatives

 public function createImageDerivatives(Collection $collection)
 {
     $collection->transform(function ($item, $key) {
         $image_styles = collect($this->getImageStyles());
         $image_derivatives = collect($this->getImageDerivatives());
         $fields = $image_derivatives->keys()->intersect($item->attributeKeys());
         foreach ($fields->all() as $field) {
             $styles = collect($image_derivatives->get($field))->intersect($image_styles->keys());
             foreach ($styles->all() as $style) {
                 // Create image derivative and add it to $item.
                 if ($new_image = $this->generateImageDerivative($item->{$field}, $style)) {
                     // We have to deal with the attribute indirectly
                     // because it is an overloaded property.
                     if ($item->hasAttribute('image_derivatives')) {
                         $item_image_derivatives = (array) $item->image_derivatives;
                     } else {
                         $item_image_derivatives = [];
                     }
                     $item_image_derivatives[$style] = $new_image;
                     $item->image_derivatives = $item_image_derivatives;
                 }
             }
         }
         return $item;
     });
 }
开发者ID:infusionweb,项目名称:laravel-remote-content-cache,代码行数:26,代码来源:Profile.php


注:本文中的Illuminate\Support\Collection::transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。