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


PHP Collection::match方法代碼示例

本文整理匯總了PHP中Cake\Collection\Collection::match方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::match方法的具體用法?PHP Collection::match怎麽用?PHP Collection::match使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\Collection\Collection的用法示例。


在下文中一共展示了Collection::match方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: index

 /**
  * Index method
  *
  * @return \Cake\Network\Response|null
  */
 public function index()
 {
     $releases = $this->Releases->find('all')->all();
     $collection = new Collection($releases);
     $attribute_names = array_unique($collection->extract('attribute_name')->toArray());
     $idps = array_unique($collection->extract('idp')->toArray());
     $releasesByIdp = $collection->groupBy('idp')->toArray();
     foreach ($idps as $idp) {
         foreach ($attribute_names as $attribute) {
             $releasesByIdPbyAttribute = $collection->match(['idp' => $idp, 'attribute_name' => $attribute]);
             $temp_result = $releasesByIdPbyAttribute->countBy(function ($result) {
                 return strtolower($result->validated) == 'fail' ? 'fail' : 'pass';
             });
             $results[$idp][$attribute] = $temp_result->toArray();
         }
     }
     # My attributes
     $persistentid_array = preg_split('/!/', $this->request->env('persistent-id'));
     $persistentid = end($persistentid_array);
     $myAttributesTemp = $this->Releases->find()->andWhere(['idp' => $this->request->env('Shib-Identity-Provider'), 'persistentid' => $persistentid])->all();
     $myAttributesCollection = new Collection($myAttributesTemp);
     $myAttributes = $myAttributesCollection->groupBy('attribute_name')->toArray();
     $this->set(compact('myAttributes'));
     $this->set('_serialize', ['myAttributes']);
     $this->set(compact('results'));
     $this->set('_serialize', ['results']);
     $this->set(compact('idps'));
     $this->set('_serialize', ['idps']);
     $this->set(compact('attribute_names'));
     $this->set('_serialize', ['attribute_names']);
 }
開發者ID:csc-it-center-for-science,項目名稱:attribute-test-service,代碼行數:36,代碼來源:ReleasesController.php

示例2: testMatch

 /**
  * Tests match
  *
  * @return void
  */
 public function testMatch()
 {
     $this->assertFalse(defined('HHVM_VERSION'), 'Broken on HHVM');
     $items = [['id' => 1, 'name' => 'foo', 'thing' => ['parent_id' => 10]], ['id' => 2, 'name' => 'bar', 'thing' => ['parent_id' => 11]], ['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]]];
     $collection = new Collection($items);
     $matched = $collection->match(['thing.parent_id' => 10, 'name' => 'baz']);
     $this->assertEquals([2 => $items[2]], $matched->toArray());
     $matched = $collection->match(['thing.parent_id' => 10]);
     $this->assertEquals([0 => $items[0], 2 => $items[2]], $matched->toArray());
     $matched = $collection->match(['thing.parent_id' => 500]);
     $this->assertEquals([], $matched->toArray());
     $matched = $collection->match(['parent_id' => 10, 'name' => 'baz']);
     $this->assertEquals([], $matched->toArray());
 }
開發者ID:ripzappa0924,項目名稱:carte0.0.1,代碼行數:19,代碼來源:CollectionTest.php


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