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


PHP PhabricatorPolicyFilter::apply方法代码示例

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


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

示例1: execute

 public final function execute()
 {
     if (!$this->viewer) {
         throw new Exception("Call setViewer() before execute()!");
     }
     $results = array();
     $filter = new PhabricatorPolicyFilter();
     $filter->setViewer($this->viewer);
     $filter->setCapability(PhabricatorPolicyCapability::CAN_VIEW);
     $filter->raisePolicyExceptions($this->raisePolicyExceptions);
     do {
         $page = $this->loadPage();
         $visible = $filter->apply($page);
         foreach ($visible as $key => $result) {
             $results[$key] = $result;
             if ($this->getLimit() && count($results) >= $this->getLimit()) {
                 break 2;
             }
         }
         if (!$this->getLimit() || count($page) < $this->getLimit()) {
             break;
         }
         $this->nextPage($page);
     } while (true);
     return $results;
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:26,代码来源:PhabricatorPolicyQuery.php

示例2: hasCapability

 public static function hasCapability(PhabricatorUser $user, PhabricatorPolicyInterface $object, $capability)
 {
     $filter = new PhabricatorPolicyFilter();
     $filter->setViewer($user);
     $filter->requireCapabilities(array($capability));
     $result = $filter->apply(array($object));
     return count($result) == 1;
 }
开发者ID:patelhardik,项目名称:phabricator,代码行数:8,代码来源:PhabricatorPolicyFilter.php

示例3: testMultipleCapabilities

 public function testMultipleCapabilities()
 {
     $object = new PhabricatorPolicyTestObject();
     $object->setCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT));
     $object->setPolicies(array(PhabricatorPolicyCapability::CAN_VIEW => PhabricatorPolicies::POLICY_USER, PhabricatorPolicyCapability::CAN_EDIT => PhabricatorPolicies::POLICY_NOONE));
     $filter = new PhabricatorPolicyFilter();
     $filter->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT));
     $filter->setViewer($this->buildUser('user'));
     $result = $filter->apply(array($object));
     $this->assertEqual(array(), $result);
 }
开发者ID:denghp,项目名称:phabricator,代码行数:11,代码来源:PhabricatorPolicyTestCase.php

示例4: execute

 /**
  * Execute the query, loading all visible results.
  *
  * @return list<PhabricatorPolicyInterface> Result objects.
  * @task exec
  */
 public final function execute()
 {
     if (!$this->viewer) {
         throw new Exception("Call setViewer() before execute()!");
     }
     $results = array();
     $filter = new PhabricatorPolicyFilter();
     $filter->setViewer($this->viewer);
     if (!$this->capabilities) {
         $capabilities = array(PhabricatorPolicyCapability::CAN_VIEW);
     } else {
         $capabilities = $this->capabilities;
     }
     $filter->requireCapabilities($capabilities);
     $filter->raisePolicyExceptions($this->raisePolicyExceptions);
     $offset = (int) $this->getOffset();
     $limit = (int) $this->getLimit();
     $count = 0;
     if ($limit) {
         $need = $offset + $limit;
     } else {
         $need = 0;
     }
     $this->willExecute();
     do {
         if ($need) {
             $this->rawResultLimit = min($need - $count, 1024);
         } else {
             $this->rawResultLimit = 0;
         }
         $page = $this->loadPage();
         $visible = $filter->apply($page);
         foreach ($visible as $key => $result) {
             ++$count;
             // If we have an offset, we just ignore that many results and start
             // storing them only once we've hit the offset. This reduces memory
             // requirements for large offsets, compared to storing them all and
             // slicing them away later.
             if ($count > $offset) {
                 $results[$key] = $result;
             }
             if ($need && $count >= $need) {
                 // If we have all the rows we need, break out of the paging query.
                 break 2;
             }
         }
         if (!$this->rawResultLimit) {
             // If we don't have a load count, we loaded all the results. We do
             // not need to load another page.
             break;
         }
         if (count($page) < $this->rawResultLimit) {
             // If we have a load count but the unfiltered results contained fewer
             // objects, we know this was the last page of objects; we do not need
             // to load another page because we can deduce it would be empty.
             break;
         }
         $this->nextPage($page);
     } while (true);
     return $results;
 }
开发者ID:rudimk,项目名称:phabricator,代码行数:67,代码来源:PhabricatorPolicyAwareQuery.php


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