本文整理汇总了PHP中PhabricatorPolicyFilter::raisePolicyExceptions方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorPolicyFilter::raisePolicyExceptions方法的具体用法?PHP PhabricatorPolicyFilter::raisePolicyExceptions怎么用?PHP PhabricatorPolicyFilter::raisePolicyExceptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhabricatorPolicyFilter
的用法示例。
在下文中一共展示了PhabricatorPolicyFilter::raisePolicyExceptions方法的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;
}
示例2: requireCapability
public static function requireCapability(PhabricatorUser $user, PhabricatorPolicyInterface $object, $capability)
{
$filter = new PhabricatorPolicyFilter();
$filter->setViewer($user);
$filter->requireCapabilities(array($capability));
$filter->raisePolicyExceptions(true);
$filter->apply(array($object));
}
示例3: getPolicyFilter
private function getPolicyFilter()
{
$filter = new PhabricatorPolicyFilter();
$filter->setViewer($this->viewer);
$capabilities = $this->getRequiredCapabilities();
$filter->requireCapabilities($capabilities);
$filter->raisePolicyExceptions($this->shouldRaisePolicyExceptions());
return $filter;
}
示例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;
}