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


PHP Collection::map方法代码示例

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


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

示例1: testCompile

 /**
  * Tests that by calling compile internal iteration operations are not done
  * more than once
  *
  * @return void
  */
 public function testCompile()
 {
     $items = ['a' => 1, 'b' => 2, 'c' => 3];
     $collection = new Collection($items);
     $callable = $this->getMock('stdClass', ['__invoke']);
     $callable->expects($this->at(0))->method('__invoke')->with(1, 'a')->will($this->returnValue(4));
     $callable->expects($this->at(1))->method('__invoke')->with(2, 'b')->will($this->returnValue(5));
     $callable->expects($this->at(2))->method('__invoke')->with(3, 'c')->will($this->returnValue(6));
     $compiled = $collection->map($callable)->compile();
     $this->assertEquals(['a' => 4, 'b' => 5, 'c' => 6], $compiled->toArray());
     $this->assertEquals(['a' => 4, 'b' => 5, 'c' => 6], $compiled->toArray());
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:18,代码来源:CollectionTest.php

示例2: override

 /**
  * Set an override for a column, columns or restore all to default
  * 
  * Pass CRUDDATA_DEFAULT_OVERRIDES (FALSE) to restore to default types for all columns
  * Pass string_name, string_value to override one column
  * Pass [
  *		string_name => string_value,
  * 		string_name => string_value
  * ] for multiple overrides at once
  * 
  * @param array|string|boolean $override
  * @param string $type
  * @return array
  */
 public function override($override = NULL, $type = 'string')
 {
     if ($override === CRUDDATA_DEFAULT_OVERRIDES) {
         $this->_clearOverrides();
     } elseif (is_string($override)) {
         $this->_columns[$override]['type'] = $type;
     } elseif (is_array($override)) {
         foreach ($override as $column => $type) {
             $this->_columns[$column]['type'] = $type;
         }
     }
     $columns = new Collection($this->columns());
     $overrides = [];
     return $columns->map(function ($value, $key) use(&$overrides) {
         return $overrides[$key] = ['type' => $value['type']];
     })->toArray();
 }
开发者ID:OrigamiStructures,项目名称:CrudViews,代码行数:31,代码来源:CrudData.php


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