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


PHP Collection::filter方法代碼示例

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


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

示例1: checkPermission

 /**
  * Checks if the provided $roleId is allowed to perform the given $action.
  *
  * @param int $roleId Role ID
  * @param string $action Action to check: create, edit, delete or publish
  * @return bool
  */
 public function checkPermission($roleId, $action)
 {
     if ($roleId == ROLE_ID_ADMINISTRATOR) {
         return true;
     }
     $this->_loadPermissions();
     $rule = $this->_permissions->filter(function ($rule) use($roleId, $action) {
         return $rule->get('role_id') == $roleId && $rule->get('action') == $action;
     })->first();
     return !empty($rule);
 }
開發者ID:quickapps-plugins,項目名稱:content,代碼行數:18,代碼來源:ContentType.php

示例2: getBlocksForColumn

 /**
  * Return all blocks to render in the given row column
  *
  * @param int $column Numeric column index, starting with 1
  * @return array
  */
 public function getBlocksForColumn($column)
 {
     $blocks = new \Cake\Collection\Collection($this->cms_blocks);
     return $blocks->filter(function ($block) use($column) {
         return $block->column_index == $column;
     })->toArray();
 }
開發者ID:scherersoftware,項目名稱:cake-cms,代碼行數:13,代碼來源:CmsRow.php

示例3: isPermitted

 public function isPermitted($permissions, $operator = OPERATOR_AND)
 {
     $session = $this->request->session()->read('Auth.User');
     if ($session['idr_admin']) {
         return true;
     }
     $acoes = new Collection($session['acoes']);
     if (is_array($permissions)) {
         if ($operator == OPERATOR_AND) {
             foreach ($permissions as $k => $p) {
                 $permitido = $acoes->filter(function ($acao, $key) use($p) {
                     return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
                 });
                 if (count($permitido->toArray()) == 0) {
                     break;
                 }
             }
         } else {
             foreach ($permissions as $k => $p) {
                 $permitido = $acoes->filter(function ($acao, $key) use($p) {
                     return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
                 });
                 if (count($permitido->toArray()) > 0) {
                     break;
                 }
             }
         }
     } else {
         $permitido = $acoes->filter(function ($acao, $key) use($permissions) {
             return mb_strtoupper($acao['tag']) == mb_strtoupper($permissions);
         });
     }
     if (count($permitido->toArray()) > 0) {
         return true;
     } else {
         return false;
     }
 }
開發者ID:ranzate,項目名稱:security,代碼行數:38,代碼來源:SecurityHelper.php

示例4: anyPermitted

 private function anyPermitted($permissions, $operator = self::OPERATOR_AND)
 {
     $session = $this->request->session()->read('Auth.User');
     if ($session['idr_admin']) {
         return true;
     }
     $acoes = new Collection($session['acoes']);
     if (is_array($permissions)) {
         if ($operator == self::OPERATOR_AND) {
             foreach ($permissions as $k => $p) {
                 $permitido = $acoes->filter(function ($acao, $key) use($p) {
                     return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
                 });
                 if (count($permitido->toArray()) == 0) {
                     break;
                 }
             }
         } else {
             foreach ($permissions as $k => $p) {
                 $permitido = $acoes->filter(function ($acao, $key) use($p) {
                     return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
                 });
                 if (count($permitido->toArray()) > 0) {
                     break;
                 }
             }
         }
     } else {
         $permitido = $acoes->filter(function ($acao, $key) use($permissions) {
             return mb_strtoupper($acao['tag']) == mb_strtoupper($permissions);
         });
     }
     if (count($permitido->toArray()) == 0) {
         throw new UnauthorizedException("Usuário da sessão não possui permissão para acessar a ação escolhida");
     }
 }
開發者ID:ranzate,項目名稱:security,代碼行數:36,代碼來源:SecurityComponent.php

示例5: testFilterChaining

 /**
  * Tests that it is possible to chain filter() as it returns a collection object
  *
  * @return void
  */
 public function testFilterChaining()
 {
     $this->assertFalse(defined('HHVM_VERSION'), 'Broken on HHVM');
     $items = ['a' => 1, 'b' => 2, 'c' => 3];
     $collection = new Collection($items);
     $callable = $this->getMock('stdClass', ['__invoke']);
     $callable->expects($this->once())->method('__invoke')->with(3, 'c');
     $filtered = $collection->filter(function ($value, $key, $iterator) {
         return $value > 2;
     });
     $this->assertInstanceOf('\\Cake\\Collection\\Collection', $filtered);
     $filtered->each($callable);
 }
開發者ID:ripzappa0924,項目名稱:carte0.0.1,代碼行數:18,代碼來源:CollectionTest.php

示例6: getType

 /**
  * Retrieves a type that should be used for a specific field
  *
  * @param string $field Name of field
  * @param string $type User-specified type
  * @return string
  */
 public function getType($field, $type)
 {
     $reflector = new ReflectionClass('Phinx\\Db\\Adapter\\AdapterInterface');
     $collection = new Collection($reflector->getConstants());
     $validTypes = $collection->filter(function ($value, $constant) {
         $value;
         return substr($constant, 0, strlen('PHINX_TYPE_')) === 'PHINX_TYPE_';
     })->toArray();
     $fieldType = $type;
     if ($type === null || !in_array($type, $validTypes)) {
         if ($type === 'primary') {
             $fieldType = 'integer';
         } elseif ($field === 'id') {
             $fieldType = 'integer';
         } elseif (in_array($field, ['created', 'modified', 'updated'])) {
             $fieldType = 'datetime';
         } else {
             $fieldType = 'string';
         }
     }
     return $fieldType;
 }
開發者ID:JesseDarellMoore,項目名稱:CS499,代碼行數:29,代碼來源:ColumnParser.php

示例7: testFilterChaining

 /**
  * Tests that it is possible to chain filter() as it returns a collection object
  *
  * @return void
  */
 public function testFilterChaining()
 {
     $items = ['a' => 1, 'b' => 2, 'c' => 3];
     $collection = new Collection($items);
     $callable = $this->getMockBuilder(\StdClass::class)->setMethods(['__invoke'])->getMock();
     $callable->expects($this->once())->method('__invoke')->with(3, 'c');
     $filtered = $collection->filter(function ($value, $key, $iterator) {
         return $value > 2;
     });
     $this->assertInstanceOf('Cake\\Collection\\Collection', $filtered);
     $filtered->each($callable);
 }
開發者ID:rashmi,項目名稱:newrepo,代碼行數:17,代碼來源:CollectionTest.php

示例8: 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:fullybaked,項目名稱:migrations,代碼行數:38,代碼來源:Table.php

示例9: _getLosers

 protected function _getLosers()
 {
     //        $gameMembershipsCollection = new Collection($this->game_memberships);
     //        $victor_member = $gameMembershipsCollection->indexBy('id')->max('points');
     //
     //        $victor['full_name'] = Hash::get($victor_member, 'member.full_name');
     //        $victor['id'] = Hash::get($victor_member, 'member.id');
     $gm_collection = new Collection($this->game_memberships);
     $victor = $gm_collection->indexBy('id')->max('points');
     $victor_id = $victor->generic_member->id;
     $losers = $gm_collection->filter(function ($gm, $key) use($victor_id) {
         return $victor_id != $gm->generic_member->id;
     });
     //        if(!$loser = $losers->first())
     //            return false;
     //        if(!($loser->member or $loser->temp_member))
     //            return false;
     $losers_array = [];
     foreach ($losers as $loser) {
         array_push($losers_array, $loser);
     }
     return $losers_array;
 }
開發者ID:abf6ug,項目名稱:statbro,代碼行數:23,代碼來源:Game.php


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