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


PHP Collection::filter方法代码示例

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


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

示例1: testFilter

 /**
  * @test Collection::filter()
  */
 public function testFilter()
 {
     $this->buildEnvironment();
     $result = $this->collection->filter('prop2', '>', 2)->fetch();
     $expect = $this->source;
     unset($expect['a1']);
     $this->assertEquals($expect, $result);
     $result = $this->collection->filter('prop2', '>=', 2)->fetch();
     $expect = $this->source;
     $this->assertEquals($expect, $result);
 }
开发者ID:timoxeen,项目名称:php-commerceml,代码行数:14,代码来源:CollectionTest.php

示例2: testFilter

 public function testFilter()
 {
     $this->collection->filter(function ($item) {
         return $item['last_name'] == 'smith';
     });
     $this->assertEquals(2, $this->collection->count());
     $this->assertContains($this->_0, $this->collection->toArray());
     $this->assertNotContains($this->_1, $this->collection->toArray());
     $this->assertNotContains($this->_2, $this->collection->toArray());
     $this->assertContains($this->_3, $this->collection->toArray());
 }
开发者ID:dtkahl,项目名称:php-array-tools,代码行数:11,代码来源:CollectionTest.php

示例3: filterPrimaryKey

 /**
  * This method is called in case a primary key was defined using the addPrimaryKey() method.
  * It currently does something only if using SQLite.
  * If a column is an auto-increment key in SQLite, it has to be a primary key and it has to defined
  * when defining the column. Phinx takes care of that so we have to make sure columns defined as autoincrement were
  * not added with the addPrimaryKey method, otherwise, SQL queries will be wrong.
  *
  * @return void
  */
 protected function filterPrimaryKey()
 {
     if ($this->getAdapter()->getAdapterType() !== 'sqlite' || empty($this->options['primary_key'])) {
         return;
     }
     $primaryKey = $this->options['primary_key'];
     if (!is_array($primaryKey)) {
         $primaryKey = [$primaryKey];
     }
     $primaryKey = array_flip($primaryKey);
     $columnsCollection = new Collection($this->columns);
     $primaryKeyColumns = $columnsCollection->filter(function ($columnDef, $key) use($primaryKey) {
         return isset($primaryKey[$columnDef->getName()]);
     })->toArray();
     if (empty($primaryKeyColumns)) {
         return;
     }
     foreach ($primaryKeyColumns as $primaryKeyColumn) {
         if ($primaryKeyColumn->isIdentity()) {
             unset($primaryKey[$primaryKeyColumn->getName()]);
         }
     }
     $primaryKey = array_flip($primaryKey);
     if (!empty($primaryKey)) {
         $this->options['primary_key'] = $primaryKey;
     } else {
         unset($this->options['primary_key']);
     }
 }
开发者ID:coretyson,项目名称:coretyson,代码行数:38,代码来源:Table.php

示例4: testFilter

 public function testFilter()
 {
     $collection = new Collection([new Bar('a'), new Bar('a'), new Bar('b'), new Bar('b')]);
     $result = $collection->filter(new FooFilter('a'));
     $this->assertNotSame($collection, $result);
     $this->assertInstanceOf(get_class($collection), $result);
     $this->assertCount(2, $result);
 }
开发者ID:Raphhh,项目名称:trex-collection,代码行数:8,代码来源:CollectionFilterTraitTest.php

示例5: filterCategory

 /**
  * @param string $input
  */
 public function filterCategory($input)
 {
     if (empty($input) || $this->collection->isEmpty()) {
         return null;
     }
     list($operand, $value) = array_values($this->getOperandAndValue($input));
     $this->collection = $this->collection->filter(function (array $entry) use($operand, $value) {
         return $this->stringComparator($entry['category'], $value, $operand);
     });
 }
开发者ID:advmaker,项目名称:LamantinParser,代码行数:13,代码来源:Filter.php

示例6: filter

 /**
  * {@inheritdoc}
  */
 public function filter(Closure $p)
 {
     $this->initialize();
     return $this->coll->filter($p);
 }
开发者ID:richardmiller,项目名称:mongodb-odm,代码行数:8,代码来源:PersistentCollection.php

示例7: buildTree

 /**
  * @param \Collection $rowset
  * @return mixed
  */
 private function buildTree($rowset)
 {
     // extract only main categories
     $parents = $rowset->where('parent_id', null)->keyBy('id');
     // extract only children categories
     $children = $rowset->filter(function ($item) {
         return $item->parent_id != null;
     })->groupBy('parent_id');
     // we merge children with parent element
     foreach ($children as $parentId => $child) {
         $parents[$parentId]->subs = $child;
     }
     return $parents;
 }
开发者ID:furious-programming,项目名称:coyote,代码行数:18,代码来源:ForumRepository.php

示例8: filter

 public function filter($filterer, $op = '===')
 {
     $collection = new Collection($this->store);
     return $collection->filter($filterer, $op);
 }
开发者ID:MrHidalgo,项目名称:css-crush,代码行数:5,代码来源:Iterator.php


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