code
stringlengths 15
9.96M
| docstring
stringlengths 1
10.1k
| func_name
stringlengths 1
124
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 6
186
| url
stringlengths 50
236
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function setWait($wait) {
$this->wait = $wait;
return $this;
} | Set duration (in seconds) to wait for the file lock. | setWait | php | phorgeit/phorge | src/infrastructure/cache/PhutilOnDiskKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilOnDiskKeyValueCache.php | Apache-2.0 |
public function setCacheFile($file) {
$this->cacheFile = $file;
return $this;
} | @task storage | setCacheFile | php | phorgeit/phorge | src/infrastructure/cache/PhutilOnDiskKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilOnDiskKeyValueCache.php | Apache-2.0 |
private function loadCache($hold_lock) {
if ($this->lock) {
throw new Exception(
pht(
'Trying to %s with a lock!',
__FUNCTION__.'()'));
}
$lock = PhutilFileLock::newForPath($this->getCacheFile().'.lock');
try {
$lock->lock($this->wait);
} catch (PhutilLockException $ex) {
if ($hold_lock) {
throw $ex;
} else {
$this->cache = array();
return;
}
}
try {
$this->cache = array();
if (Filesystem::pathExists($this->getCacheFile())) {
$cache = unserialize(Filesystem::readFile($this->getCacheFile()));
if ($cache) {
$this->cache = $cache;
}
}
} catch (Exception $ex) {
$lock->unlock();
throw $ex;
}
if ($hold_lock) {
$this->lock = $lock;
} else {
$lock->unlock();
}
} | @task storage | loadCache | php | phorgeit/phorge | src/infrastructure/cache/PhutilOnDiskKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilOnDiskKeyValueCache.php | Apache-2.0 |
private function saveCache() {
if (!$this->lock) {
throw new PhutilInvalidStateException('loadCache');
}
// We're holding a lock so we're safe to do a write to a well-known file.
// Write to the same directory as the cache so the rename won't imply a
// copy across volumes.
$new = $this->getCacheFile().'.new';
Filesystem::writeFile($new, serialize($this->cache));
Filesystem::rename($new, $this->getCacheFile());
$this->lock->unlock();
$this->lock = null;
} | @task storage | saveCache | php | phorgeit/phorge | src/infrastructure/cache/PhutilOnDiskKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilOnDiskKeyValueCache.php | Apache-2.0 |
private function getCacheFile() {
if (!$this->cacheFile) {
throw new PhutilInvalidStateException('setCacheFile');
}
return $this->cacheFile;
} | @task storage | getCacheFile | php | phorgeit/phorge | src/infrastructure/cache/PhutilOnDiskKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilOnDiskKeyValueCache.php | Apache-2.0 |
public function setProfiler(PhutilServiceProfiler $profiler) {
$this->profiler = $profiler;
return $this;
} | Set a profiler for cache operations.
@param PhutilServiceProfiler $profiler Service profiler.
@return $this
@task kvimpl | setProfiler | php | phorgeit/phorge | src/infrastructure/cache/PhutilKeyValueCacheProfiler.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilKeyValueCacheProfiler.php | Apache-2.0 |
public function getProfiler() {
return $this->profiler;
} | Get the current profiler.
@return PhutilServiceProfiler|null Profiler, or null if none is set.
@task kvimpl | getProfiler | php | phorgeit/phorge | src/infrastructure/cache/PhutilKeyValueCacheProfiler.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilKeyValueCacheProfiler.php | Apache-2.0 |
public function setLimit($limit) {
$this->limit = $limit;
return $this;
} | Set a limit on the number of keys this cache may contain.
When too many keys are inserted, the oldest keys are removed from the
cache. Setting a limit of `0` disables the cache.
@param int $limit Maximum number of items to store in the cache.
@return $this | setLimit | php | phorgeit/phorge | src/infrastructure/cache/PhutilInRequestKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilInRequestKeyValueCache.php | Apache-2.0 |
public function setCacheDirectory($directory) {
$this->cacheDirectory = rtrim($directory, '/').'/';
return $this;
} | @task storage | setCacheDirectory | php | phorgeit/phorge | src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | Apache-2.0 |
private function getCacheDirectory() {
if (!$this->cacheDirectory) {
throw new PhutilInvalidStateException('setCacheDirectory');
}
return $this->cacheDirectory;
} | @task storage | getCacheDirectory | php | phorgeit/phorge | src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | Apache-2.0 |
private function getKeyFile($key) {
// Colon is a drive separator on Windows.
$key = str_replace(':', '_', $key);
// NOTE: We add ".cache" to each file so we don't get a collision if you
// set the keys "a" and "a/b". Without ".cache", the file "a" would need
// to be both a file and a directory.
return $this->getCacheDirectory().$key.'.cache';
} | @task storage | getKeyFile | php | phorgeit/phorge | src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | Apache-2.0 |
private function validateKeys(array $keys) {
foreach ($keys as $key) {
// NOTE: Use of "." is reserved for ".lock", "key.new" and "key.cache".
// Use of "_" is reserved for converting ":".
if (!preg_match('@^[a-zA-Z0-9/:-]+$@', $key)) {
throw new Exception(
pht(
"Invalid key '%s': directory caches may only contain letters, ".
"numbers, hyphen, colon and slash.",
$key));
}
}
} | @task storage | validateKeys | php | phorgeit/phorge | src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | Apache-2.0 |
private function lockCache($wait = 0) {
if ($this->lock) {
throw new Exception(
pht(
'Trying to %s with a lock!',
__FUNCTION__.'()'));
}
if (!Filesystem::pathExists($this->getCacheDirectory())) {
Filesystem::createDirectory($this->getCacheDirectory(), 0755, true);
}
$lock = PhutilFileLock::newForPath($this->getCacheDirectory().'.lock');
$lock->lock($wait);
$this->lock = $lock;
} | @task storage | lockCache | php | phorgeit/phorge | src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | Apache-2.0 |
private function unlockCache() {
if (!$this->lock) {
throw new PhutilInvalidStateException('lockCache');
}
$this->lock->unlock();
$this->lock = null;
} | @task storage | unlockCache | php | phorgeit/phorge | src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/cache/PhutilDirectoryKeyValueCache.php | Apache-2.0 |
final public function getSource() {
return $this->source;
} | Get the internal source name
This is usually coming from a SOURCECONST constant.
@return string|null | getSource | php | phorgeit/phorge | src/infrastructure/contentsource/PhabricatorContentSource.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/contentsource/PhabricatorContentSource.php | Apache-2.0 |
protected function formatWhereClause(
AphrontDatabaseConnection $conn,
array $parts) {
$parts = $this->flattenSubclause($parts);
if (!$parts) {
return qsprintf($conn, '');
}
return qsprintf($conn, 'WHERE %LA', $parts);
} | @task format | formatWhereClause | php | phorgeit/phorge | src/infrastructure/query/PhabricatorQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/PhabricatorQuery.php | Apache-2.0 |
protected function formatSelectClause(
AphrontDatabaseConnection $conn,
array $parts) {
$parts = $this->flattenSubclause($parts);
if (!$parts) {
throw new Exception(pht('Can not build empty SELECT clause!'));
}
return qsprintf($conn, 'SELECT %LQ', $parts);
} | @task format | formatSelectClause | php | phorgeit/phorge | src/infrastructure/query/PhabricatorQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/PhabricatorQuery.php | Apache-2.0 |
protected function formatJoinClause(
AphrontDatabaseConnection $conn,
array $parts) {
$parts = $this->flattenSubclause($parts);
if (!$parts) {
return qsprintf($conn, '');
}
return qsprintf($conn, '%LJ', $parts);
} | @task format | formatJoinClause | php | phorgeit/phorge | src/infrastructure/query/PhabricatorQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/PhabricatorQuery.php | Apache-2.0 |
protected function formatHavingClause(
AphrontDatabaseConnection $conn,
array $parts) {
$parts = $this->flattenSubclause($parts);
if (!$parts) {
return qsprintf($conn, '');
}
return qsprintf($conn, 'HAVING %LA', $parts);
} | @task format | formatHavingClause | php | phorgeit/phorge | src/infrastructure/query/PhabricatorQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/PhabricatorQuery.php | Apache-2.0 |
private function flattenSubclause(array $parts) {
$result = array();
foreach ($parts as $part) {
if (is_array($part)) {
foreach ($this->flattenSubclause($part) as $subpart) {
$result[] = $subpart;
}
} else if (($part !== null) && strlen($part)) {
$result[] = $part;
}
}
return $result;
} | @task format | flattenSubclause | php | phorgeit/phorge | src/infrastructure/query/PhabricatorQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/PhabricatorQuery.php | Apache-2.0 |
protected function getPrimaryTableAlias() {
return null;
} | Return the alias this query uses to identify the primary table.
Some automatic query constructions may need to be qualified with a table
alias if the query performs joins which make column names ambiguous. If
this is the case, return the alias for the primary table the query
uses; generally the object table which has `id` and `phid` columns.
@return string|null Alias for the primary table, or null. | getPrimaryTableAlias | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function buildSelectClause(AphrontDatabaseConnection $conn) {
$parts = $this->buildSelectClauseParts($conn);
return $this->formatSelectClause($conn, $parts);
} | @task clauses | buildSelectClause | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function buildSelectClauseParts(AphrontDatabaseConnection $conn) {
$select = array();
$alias = $this->getPrimaryTableAlias();
if ($alias) {
$select[] = qsprintf($conn, '%T.*', $alias);
} else {
$select[] = qsprintf($conn, '*');
}
$select[] = $this->buildEdgeLogicSelectClause($conn);
$select[] = $this->buildFerretSelectClause($conn);
return $select;
} | @task clauses | buildSelectClauseParts | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function buildJoinClause(AphrontDatabaseConnection $conn) {
$joins = $this->buildJoinClauseParts($conn);
return $this->formatJoinClause($conn, $joins);
} | @task clauses | buildJoinClause | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$joins = array();
$joins[] = $this->buildEdgeLogicJoinClause($conn);
$joins[] = $this->buildApplicationSearchJoinClause($conn);
$joins[] = $this->buildNgramsJoinClause($conn);
$joins[] = $this->buildFerretJoinClause($conn);
return $joins;
} | @task clauses | buildJoinClauseParts | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
$where = $this->buildWhereClauseParts($conn);
return $this->formatWhereClause($conn, $where);
} | @task clauses | buildWhereClause | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = array();
$where[] = $this->buildPagingWhereClause($conn);
$where[] = $this->buildEdgeLogicWhereClause($conn);
$where[] = $this->buildSpacesWhereClause($conn);
$where[] = $this->buildNgramsWhereClause($conn);
$where[] = $this->buildFerretWhereClause($conn);
$where[] = $this->buildApplicationSearchWhereClause($conn);
return $where;
} | @task clauses | buildWhereClauseParts | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function buildHavingClause(AphrontDatabaseConnection $conn) {
$having = $this->buildHavingClauseParts($conn);
$having[] = $this->buildPagingHavingClause($conn);
return $this->formatHavingClause($conn, $having);
} | @task clauses | buildHavingClause | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function buildHavingClauseParts(AphrontDatabaseConnection $conn) {
$having = array();
$having[] = $this->buildEdgeLogicHavingClause($conn);
return $having;
} | @task clauses | buildHavingClauseParts | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function buildGroupClause(AphrontDatabaseConnection $conn) {
if (!$this->shouldGroupQueryResultRows()) {
return qsprintf($conn, '');
}
return qsprintf(
$conn,
'GROUP BY %Q',
$this->getApplicationSearchObjectPHIDColumn($conn));
} | @task clauses | buildGroupClause | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function shouldGroupQueryResultRows() {
if ($this->shouldGroupEdgeLogicResultRows()) {
return true;
}
if ($this->getApplicationSearchMayJoinMultipleRows()) {
return true;
}
if ($this->shouldGroupNgramResultRows()) {
return true;
}
if ($this->shouldGroupFerretResultRows()) {
return true;
}
return false;
} | @task clauses | shouldGroupQueryResultRows | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
public function setOrder($order) {
$aliases = $this->getBuiltinOrderAliasMap();
if (empty($aliases[$order])) {
throw new Exception(
pht(
'Query "%s" does not support a builtin order "%s". Supported orders '.
'are: %s.',
get_class($this),
$order,
implode(', ', array_keys($aliases))));
}
$this->builtinOrder = $aliases[$order];
$this->orderVector = null;
return $this;
} | Select a result ordering.
This is a high-level method which selects an ordering from a predefined
list of builtin orders, as provided by @{method:getBuiltinOrders}. These
options are user-facing and not exhaustive, but are generally convenient
and meaningful.
You can also use @{method:setOrderVector} to specify a low-level ordering
across individual orderable columns. This offers greater control but is
also more involved.
@param string $order Key of a builtin order supported by this query.
@return $this
@task order | setOrder | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
public function setGroupVector($vector) {
$this->groupVector = $vector;
$this->orderVector = null;
return $this;
} | Set a grouping order to apply before primary result ordering.
This allows you to preface the query order vector with additional orders,
so you can effect "group by" queries while still respecting "order by".
This is a high-level method which works alongside @{method:setOrder}. For
lower-level control over order vectors, use @{method:setOrderVector}.
@param PhabricatorQueryOrderVector|list<string> $vector List of order
keys.
@return $this
@task order | setGroupVector | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function getOrderVector() {
if (!$this->orderVector) {
if ($this->builtinOrder !== null) {
$builtin_order = idx($this->getBuiltinOrders(), $this->builtinOrder);
$vector = $builtin_order['vector'];
} else {
$vector = $this->getDefaultOrderVector();
}
if ($this->groupVector) {
$group = PhabricatorQueryOrderVector::newFromVector($this->groupVector);
$group->appendVector($vector);
$vector = $group;
}
$vector = PhabricatorQueryOrderVector::newFromVector($vector);
// We call setOrderVector() here to apply checks to the default vector.
// This catches any errors in the implementation.
$this->setOrderVector($vector);
}
return $this->orderVector;
} | Get the effective order vector.
@return PhabricatorQueryOrderVector Effective vector.
@task order | getOrderVector | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function getDefaultOrderVector() {
return array('id');
} | @task order | getDefaultOrderVector | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
public function withApplicationSearchContainsConstraint(
PhabricatorCustomFieldIndexStorage $index,
$value) {
$values = (array)$value;
$data_values = array();
$constraint_values = array();
foreach ($values as $value) {
if ($value instanceof PhabricatorQueryConstraint) {
$constraint_values[] = $value;
} else {
$data_values[] = $value;
}
}
$alias = 'appsearch_'.count($this->applicationSearchConstraints);
$this->applicationSearchConstraints[] = array(
'type' => $index->getIndexValueType(),
'cond' => '=',
'table' => $index->getTableName(),
'index' => $index->getIndexKey(),
'alias' => $alias,
'value' => $values,
'data' => $data_values,
'constraints' => $constraint_values,
);
return $this;
} | Constrain the query with an ApplicationSearch index, requiring field values
contain at least one of the values in a set.
This constraint can build the most common types of queries, like:
- Find users with shirt sizes "X" or "XL".
- Find shoes with size "13".
@param PhabricatorCustomFieldIndexStorage $index Table where the index is
stored.
@param string|list<string> $value One or more values to filter by.
@return $this
@task appsearch | withApplicationSearchContainsConstraint | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
public function withApplicationSearchRangeConstraint(
PhabricatorCustomFieldIndexStorage $index,
$min,
$max) {
$index_type = $index->getIndexValueType();
if ($index_type != 'int') {
throw new Exception(
pht(
'Attempting to apply a range constraint to a field with index type '.
'"%s", expected type "%s".',
$index_type,
'int'));
}
$alias = 'appsearch_'.count($this->applicationSearchConstraints);
$this->applicationSearchConstraints[] = array(
'type' => $index->getIndexValueType(),
'cond' => 'range',
'table' => $index->getTableName(),
'index' => $index->getIndexKey(),
'alias' => $alias,
'value' => array($min, $max),
'data' => null,
'constraints' => null,
);
return $this;
} | Constrain the query with an ApplicationSearch index, requiring values
exist in a given range.
This constraint is useful for expressing date ranges:
- Find events between July 1st and July 7th.
The ends of the range are inclusive, so a `$min` of `3` and a `$max` of
`5` will match fields with values `3`, `4`, or `5`. Providing `null` for
either end of the range will leave that end of the constraint open.
@param PhabricatorCustomFieldIndexStorage $index Table where the index is
stored.
@param int|null $min Minimum permissible value, inclusive.
@param int|null $max Maximum permissible value, inclusive.
@return $this
@task appsearch | withApplicationSearchRangeConstraint | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function getApplicationSearchObjectPHIDColumn(
AphrontDatabaseConnection $conn) {
if ($this->getPrimaryTableAlias()) {
return qsprintf($conn, '%T.phid', $this->getPrimaryTableAlias());
} else {
return qsprintf($conn, 'phid');
}
} | Get the name of the query's primary object PHID column, for constructing
JOIN clauses. Normally (and by default) this is just `"phid"`, but it may
be something more exotic.
See @{method:getPrimaryTableAlias} if the column needs to be qualified with
a table alias.
@param AphrontDatabaseConnection $conn Connection executing queries.
@return PhutilQueryString Column name.
@task appsearch | getApplicationSearchObjectPHIDColumn | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function getApplicationSearchMayJoinMultipleRows() {
foreach ($this->applicationSearchConstraints as $constraint) {
$type = $constraint['type'];
$value = $constraint['value'];
$cond = $constraint['cond'];
switch ($cond) {
case '=':
switch ($type) {
case 'string':
case 'int':
if (count($value) > 1) {
return true;
}
break;
default:
throw new Exception(pht('Unknown index type "%s"!', $type));
}
break;
case 'range':
// NOTE: It's possible to write a custom field where multiple rows
// match a range constraint, but we don't currently ship any in the
// upstream and I can't immediately come up with cases where this
// would make sense.
break;
default:
throw new Exception(pht('Unknown constraint condition "%s"!', $cond));
}
}
return false;
} | Determine if the JOINs built by ApplicationSearch might cause each primary
object to return multiple result rows. Generally, this means the query
needs an extra GROUP BY clause.
@return bool True if the query may return multiple rows for each object.
@task appsearch | getApplicationSearchMayJoinMultipleRows | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function buildApplicationSearchGroupClause(
AphrontDatabaseConnection $conn) {
if ($this->getApplicationSearchMayJoinMultipleRows()) {
return qsprintf(
$conn,
'GROUP BY %Q',
$this->getApplicationSearchObjectPHIDColumn($conn));
} else {
return qsprintf($conn, '');
}
} | Construct a GROUP BY clause appropriate for ApplicationSearch constraints.
@param AphrontDatabaseConnection $conn Connection executing the query.
@return string Group clause.
@task appsearch | buildApplicationSearchGroupClause | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
protected function isCustomFieldOrderKey($key) {
$prefix = 'custom.';
return !strncmp($key, $prefix, strlen($prefix));
} | @task customfield | isCustomFieldOrderKey | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
public function withEdgeLogicConstraints($edge_type, array $constraints) {
assert_instances_of($constraints, 'PhabricatorQueryConstraint');
$constraints = mgroup($constraints, 'getOperator');
foreach ($constraints as $operator => $list) {
foreach ($list as $item) {
$this->edgeLogicConstraints[$edge_type][$operator][] = $item;
}
}
$this->edgeLogicConstraintsAreValid = false;
return $this;
} | @return $this
@task edgelogic | withEdgeLogicConstraints | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
public function buildEdgeLogicHavingClause(AphrontDatabaseConnection $conn) {
$having = array();
foreach ($this->edgeLogicConstraints as $type => $constraints) {
foreach ($constraints as $operator => $list) {
$alias = $this->getEdgeLogicTableAlias($operator, $type);
switch ($operator) {
case PhabricatorQueryConstraint::OPERATOR_AND:
if (count($list) > 1) {
$having[] = qsprintf(
$conn,
'%T = %d',
$this->buildEdgeLogicTableAliasCount($alias),
count($list));
}
break;
case PhabricatorQueryConstraint::OPERATOR_ANCESTOR:
if (count($list) > 1) {
$having[] = qsprintf(
$conn,
'%T = %d',
$this->buildEdgeLogicTableAliasAncestor($alias),
count($list));
}
break;
}
}
}
return $having;
} | @task edgelogic | buildEdgeLogicHavingClause | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
public function shouldGroupEdgeLogicResultRows() {
foreach ($this->edgeLogicConstraints as $type => $constraints) {
foreach ($constraints as $operator => $list) {
switch ($operator) {
case PhabricatorQueryConstraint::OPERATOR_NOT:
case PhabricatorQueryConstraint::OPERATOR_AND:
case PhabricatorQueryConstraint::OPERATOR_OR:
if (count($list) > 1) {
return true;
}
break;
case PhabricatorQueryConstraint::OPERATOR_ANCESTOR:
// NOTE: We must always group query results rows when using an
// "ANCESTOR" operator because a single task may be related to
// two different descendants of a particular ancestor. For
// discussion, see T12753.
return true;
case PhabricatorQueryConstraint::OPERATOR_NULL:
case PhabricatorQueryConstraint::OPERATOR_ONLY:
return true;
}
}
}
return false;
} | @task edgelogic | shouldGroupEdgeLogicResultRows | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
private function getEdgeLogicTableAlias($operator, $type) {
return 'edgelogic_'.$operator.'_'.$type;
} | @task edgelogic | getEdgeLogicTableAlias | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
private function buildEdgeLogicTableAliasCount($alias) {
return $alias.'_count';
} | @task edgelogic | buildEdgeLogicTableAliasCount | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
private function buildEdgeLogicTableAliasAncestor($alias) {
return $alias.'_ancestor';
} | @task edgelogic | buildEdgeLogicTableAliasAncestor | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
private function validateEdgeLogicConstraints() {
if ($this->edgeLogicConstraintsAreValid) {
return $this;
}
foreach ($this->edgeLogicConstraints as $type => $constraints) {
foreach ($constraints as $operator => $list) {
switch ($operator) {
case PhabricatorQueryConstraint::OPERATOR_EMPTY:
throw new PhabricatorEmptyQueryException(
pht('This query specifies an empty constraint.'));
}
}
}
// This should probably be more modular, eventually, but we only do
// project-based edge logic today.
$project_phids = $this->getEdgeLogicValues(
array(
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
),
array(
PhabricatorQueryConstraint::OPERATOR_AND,
PhabricatorQueryConstraint::OPERATOR_OR,
PhabricatorQueryConstraint::OPERATOR_NOT,
PhabricatorQueryConstraint::OPERATOR_ANCESTOR,
));
if ($project_phids) {
$projects = id(new PhabricatorProjectQuery())
->setViewer($this->getViewer())
->setParentQuery($this)
->withPHIDs($project_phids)
->execute();
$projects = mpull($projects, null, 'getPHID');
foreach ($project_phids as $phid) {
if (empty($projects[$phid])) {
throw new PhabricatorEmptyQueryException(
pht(
'This query is constrained by a project you do not have '.
'permission to see.'));
}
}
}
$op_and = PhabricatorQueryConstraint::OPERATOR_AND;
$op_or = PhabricatorQueryConstraint::OPERATOR_OR;
$op_ancestor = PhabricatorQueryConstraint::OPERATOR_ANCESTOR;
foreach ($this->edgeLogicConstraints as $type => $constraints) {
foreach ($constraints as $operator => $list) {
switch ($operator) {
case PhabricatorQueryConstraint::OPERATOR_ONLY:
if (count($list) > 1) {
throw new PhabricatorEmptyQueryException(
pht(
'This query specifies only() more than once.'));
}
$have_and = idx($constraints, $op_and);
$have_or = idx($constraints, $op_or);
$have_ancestor = idx($constraints, $op_ancestor);
if (!$have_and && !$have_or && !$have_ancestor) {
throw new PhabricatorEmptyQueryException(
pht(
'This query specifies only(), but no other constraints '.
'which it can apply to.'));
}
break;
}
}
}
$this->edgeLogicConstraintsAreValid = true;
return $this;
} | Validate edge logic constraints for the query.
@return $this
@task edgelogic | validateEdgeLogicConstraints | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
public function withSpacePHIDs(array $space_phids) {
$object = $this->newResultObject();
if (!$object) {
throw new Exception(
pht(
'This query (of class "%s") does not implement newResultObject(), '.
'but must implement this method to enable support for Spaces.',
get_class($this)));
}
if (!($object instanceof PhabricatorSpacesInterface)) {
throw new Exception(
pht(
'This query (of class "%s") returned an object of class "%s" from '.
'getNewResultObject(), but it does not implement the required '.
'interface ("%s"). Objects must implement this interface to enable '.
'Spaces support.',
get_class($this),
get_class($object),
'PhabricatorSpacesInterface'));
}
$this->spacePHIDs = $space_phids;
return $this;
} | Constrain the query to return results from only specific Spaces.
Pass a list of Space PHIDs, or `null` to represent the default space. Only
results in those Spaces will be returned.
Queries are always constrained to include only results from spaces the
viewer has access to.
@param list<string|null> $space_phids PHIDs of the spaces.
@task spaces | withSpacePHIDs | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php | Apache-2.0 |
final public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
} | Set the viewer who is executing the query. Results will be filtered
according to the viewer's capabilities. You must set a viewer to execute
a policy query.
@param PhabricatorUser $viewer The viewing user.
@return $this
@task config | setViewer | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
final public function getViewer() {
return $this->viewer;
} | Get the query's viewer.
@return PhabricatorUser The viewing user.
@task config | getViewer | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
final public function setParentQuery(PhabricatorPolicyAwareQuery $query) {
$this->parentQuery = $query;
return $this;
} | Set the parent query of this query. This is useful for nested queries so
that configuration like whether or not to raise policy exceptions is
seamlessly passed along to child queries.
@return $this
@task config | setParentQuery | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
final public function getParentQuery() {
return $this->parentQuery;
} | Get the parent query. See @{method:setParentQuery} for discussion.
@return PhabricatorPolicyAwareQuery The parent query.
@task config | getParentQuery | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
final public function setRaisePolicyExceptions($bool) {
$this->raisePolicyExceptions = $bool;
return $this;
} | Hook to configure whether this query should raise policy exceptions.
@return $this
@task config | setRaisePolicyExceptions | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
final public function shouldRaisePolicyExceptions() {
return (bool)$this->raisePolicyExceptions;
} | @return bool
@task config | shouldRaisePolicyExceptions | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
final public function requireCapabilities(array $capabilities) {
$this->capabilities = $capabilities;
return $this;
} | @task config | requireCapabilities | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
final public function execute() {
if (!$this->viewer) {
throw new PhutilInvalidStateException('setViewer');
}
$parent_query = $this->getParentQuery();
if ($parent_query && ($this->raisePolicyExceptions === null)) {
$this->setRaisePolicyExceptions(
$parent_query->shouldRaisePolicyExceptions());
}
$results = array();
$filter = $this->getPolicyFilter();
$offset = (int)$this->getOffset();
$limit = (int)$this->getLimit();
$count = 0;
if ($limit) {
$need = $offset + $limit;
} else {
$need = 0;
}
$this->willExecute();
// If we examine and filter significantly more objects than the query
// limit, we stop early. This prevents us from looping through a huge
// number of records when the viewer can see few or none of them. See
// T11773 for some discussion.
$this->isOverheated = false;
// See T13386. If we are on an old offset-based paging workflow, we need
// to base the overheating limit on both the offset and limit.
$overheat_limit = $need * 10;
$total_seen = 0;
do {
if ($need) {
$this->rawResultLimit = min($need - $count, 1024);
} else {
$this->rawResultLimit = 0;
}
if ($this->canViewerUseQueryApplication()) {
try {
$page = $this->loadPage();
} catch (PhabricatorEmptyQueryException $ex) {
$page = array();
}
} else {
$page = array();
}
$total_seen += count($page);
if ($page) {
$maybe_visible = $this->willFilterPage($page);
if ($maybe_visible) {
$maybe_visible = $this->applyWillFilterPageExtensions($maybe_visible);
}
} else {
$maybe_visible = array();
}
if ($this->shouldDisablePolicyFiltering()) {
$visible = $maybe_visible;
} else {
$visible = $filter->apply($maybe_visible);
$policy_filtered = array();
foreach ($maybe_visible as $key => $object) {
if (empty($visible[$key])) {
$phid = $object->getPHID();
if ($phid) {
$policy_filtered[$phid] = $phid;
}
}
}
$this->addPolicyFilteredPHIDs($policy_filtered);
}
if ($visible) {
$visible = $this->didFilterPage($visible);
}
$removed = array();
foreach ($maybe_visible as $key => $object) {
if (empty($visible[$key])) {
$removed[$key] = $object;
}
}
$this->didFilterResults($removed);
// NOTE: We call "nextPage()" before checking if we've found enough
// results because we want to build the internal cursor object even
// if we don't need to execute another query: the internal cursor may
// be used by a parent query that is using this query to translate an
// external cursor into an internal cursor.
$this->nextPage($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;
}
if (!$this->disableOverheating) {
if ($overheat_limit && ($total_seen >= $overheat_limit)) {
$this->isOverheated = true;
if (!$this->returnPartialResultsOnOverheat) {
throw new Exception(
pht(
'Query (of class "%s") overheated: examined more than %s '.
'raw rows without finding %s visible objects.',
get_class($this),
new PhutilNumber($overheat_limit),
new PhutilNumber($need)));
}
break;
}
}
} while (true);
$results = $this->didLoadResults($results);
return $results;
} | Execute the query, loading all visible results.
@return list<PhabricatorPolicyInterface> Result objects.
@task exec | execute | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
public function getPolicyFilteredPHIDs() {
return $this->policyFilteredPHIDs;
} | Return a map of all object PHIDs which were loaded in the query but
filtered out by policy constraints. This allows a caller to distinguish
between objects which do not exist (or, at least, were filtered at the
content level) and objects which exist but aren't visible.
@return map<string, string> Map of object PHIDs which were filtered
by policies.
@task exec | getPolicyFilteredPHIDs | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
public function putObjectsInWorkspace(array $objects) {
$parent = $this->getParentQuery();
if ($parent) {
$parent->putObjectsInWorkspace($objects);
return $this;
}
assert_instances_of($objects, 'PhabricatorPolicyInterface');
$viewer_fragment = $this->getViewer()->getCacheFragment();
// The workspace is scoped per viewer to prevent accidental contamination.
if (empty($this->workspace[$viewer_fragment])) {
$this->workspace[$viewer_fragment] = array();
}
$this->workspace[$viewer_fragment] += $objects;
return $this;
} | Put a map of objects into the query workspace. Many queries perform
subqueries, which can eventually end up loading the same objects more than
once (often to perform policy checks).
For example, loading a user may load the user's profile image, which might
load the user object again in order to verify that the viewer has
permission to see the file.
The "query workspace" allows queries to load objects from elsewhere in a
query block instead of refetching them.
When using the query workspace, it's important to obey two rules:
**Never put objects into the workspace which the viewer may not be able
to see**. You need to apply all policy filtering //before// putting
objects in the workspace. Otherwise, subqueries may read the objects and
use them to permit access to content the user shouldn't be able to view.
**Fully enrich objects pulled from the workspace.** After pulling objects
from the workspace, you still need to load and attach any additional
content the query requests. Otherwise, a query might return objects
without requested content.
Generally, you do not need to update the workspace yourself: it is
automatically populated as a side effect of objects surviving policy
filtering.
@param map<phid, PhabricatorPolicyInterface> $objects Objects to add to
the query workspace.
@return $this
@task workspace | putObjectsInWorkspace | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
public function getObjectsFromWorkspace(array $phids) {
$parent = $this->getParentQuery();
if ($parent) {
return $parent->getObjectsFromWorkspace($phids);
}
$viewer_fragment = $this->getViewer()->getCacheFragment();
$results = array();
foreach ($phids as $key => $phid) {
if (isset($this->workspace[$viewer_fragment][$phid])) {
$results[$phid] = $this->workspace[$viewer_fragment][$phid];
unset($phids[$key]);
}
}
return $results;
} | Retrieve objects from the query workspace. For more discussion about the
workspace mechanism, see @{method:putObjectsInWorkspace}. This method
searches both the current query's workspace and the workspaces of parent
queries.
@param list<string> $phids List of PHIDs to retrieve.
@return $this
@task workspace | getObjectsFromWorkspace | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
public function putPHIDsInFlight(array $phids) {
foreach ($phids as $phid) {
$this->inFlightPHIDs[$phid] = $phid;
}
return $this;
} | Mark PHIDs as in flight.
PHIDs which are "in flight" are actively being queried for. Using this
list can prevent infinite query loops by aborting queries which cycle.
@param list<string> $phids List of PHIDs which are now in flight.
@return $this | putPHIDsInFlight | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
public function getPHIDsInFlight() {
$results = $this->inFlightPHIDs;
if ($this->getParentQuery()) {
$results += $this->getParentQuery()->getPHIDsInFlight();
}
return $results;
} | Get PHIDs which are currently in flight.
PHIDs which are "in flight" are actively being queried for.
@return map<string, string> PHIDs currently in flight. | getPHIDsInFlight | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
final protected function getRawResultLimit() {
return $this->rawResultLimit;
} | Get the number of results @{method:loadPage} should load. If the value is
0, @{method:loadPage} should load all available results.
@return int The number of results to load, or 0 for all results.
@task policyimpl | getRawResultLimit | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
protected function willExecute() {
return;
} | Hook invoked before query execution. Generally, implementations should
reset any internal cursors.
@return void
@task policyimpl | willExecute | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
protected function willFilterPage(array $page) {
return $page;
} | Hook for applying a page filter prior to the privacy filter. This allows
you to drop some items from the result set without creating problems with
pagination or cursor updates. You can also load and attach data which is
required to perform policy filtering.
Generally, you should load non-policy data and perform non-policy filtering
later, in @{method:didFilterPage}. Strictly fewer objects will make it that
far (so the program will load less data) and subqueries from that context
can use the query workspace to further reduce query load.
This method will only be called if data is available. Implementations
do not need to handle the case of no results specially.
@param list<wild> $page Results from `loadPage()`.
@return list<PhabricatorPolicyInterface> Objects for policy filtering.
@task policyimpl | willFilterPage | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
protected function didFilterPage(array $page) {
return $page;
} | Hook for performing additional non-policy loading or filtering after an
object has satisfied all policy checks. Generally, this means loading and
attaching related data.
Subqueries executed during this phase can use the query workspace, which
may improve performance or make circular policies resolvable. Data which
is not necessary for policy filtering should generally be loaded here.
This callback can still filter objects (for example, if attachable data
is discovered to not exist), but should not do so for policy reasons.
This method will only be called if data is available. Implementations do
not need to handle the case of no results specially.
@param list<wild> $page Results from @{method:willFilterPage()}.
@return list<PhabricatorPolicyInterface> Objects after additional
non-policy processing. | didFilterPage | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
protected function didFilterResults(array $results) {
return;
} | Hook for removing filtered results from alternate result sets. This
hook will be called with any objects which were returned by the query but
filtered for policy reasons. The query should remove them from any cached
or partial result sets.
@param list<wild> $results List of objects that should not be returned by
alternate result mechanisms.
@return void
@task policyimpl | didFilterResults | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
protected function didLoadResults(array $results) {
return $results;
} | Hook for applying final adjustments before results are returned. This is
used by @{class:PhabricatorCursorPagedPolicyAwareQuery} to reverse results
that are queried during reverse paging.
@param list<PhabricatorPolicyInterface> $results Query results.
@return list<PhabricatorPolicyInterface> Final results.
@task policyimpl | didLoadResults | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
protected function shouldDisablePolicyFiltering() {
return false;
} | Allows a subclass to disable policy filtering. This method is dangerous.
It should be used only if the query loads data which has already been
filtered (for example, because it wraps some other query which uses
normal policy filtering).
@return bool True to disable all policy filtering.
@task policyimpl | shouldDisablePolicyFiltering | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
public function canViewerUseQueryApplication() {
$class = $this->getQueryApplicationClass();
if (!$class) {
return true;
}
$viewer = $this->getViewer();
return PhabricatorApplication::isClassInstalledForViewer($class, $viewer);
} | Determine if the viewer has permission to use this query's application.
For queries which aren't part of an application, this method always returns
true.
@return bool True if the viewer has application-level permission to
execute the query. | canViewerUseQueryApplication | php | phorgeit/phorge | src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php | Apache-2.0 |
public function withSourcePHIDs(array $source_phids) {
if (!$source_phids) {
throw new Exception(
pht(
'Edge list passed to "withSourcePHIDs(...)" is empty, but it must '.
'be nonempty.'));
}
$this->sourcePHIDs = $source_phids;
return $this;
} | Find edges originating at one or more source PHIDs. You MUST provide this
to execute an edge query.
@param list $source_phids List of source PHIDs.
@return $this
@task config | withSourcePHIDs | php | phorgeit/phorge | src/infrastructure/edges/query/PhabricatorEdgeQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/edges/query/PhabricatorEdgeQuery.php | Apache-2.0 |
public function withDestinationPHIDs(array $dest_phids) {
$this->destPHIDs = $dest_phids;
return $this;
} | Find edges terminating at one or more destination PHIDs.
@param list $dest_phids List of destination PHIDs.
@return $this | withDestinationPHIDs | php | phorgeit/phorge | src/infrastructure/edges/query/PhabricatorEdgeQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/edges/query/PhabricatorEdgeQuery.php | Apache-2.0 |
public function withEdgeTypes(array $types) {
$this->edgeTypes = $types;
return $this;
} | Find edges of specific types.
@param list $types List of PhabricatorEdgeConfig type constants.
@return $this
@task config | withEdgeTypes | php | phorgeit/phorge | src/infrastructure/edges/query/PhabricatorEdgeQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/edges/query/PhabricatorEdgeQuery.php | Apache-2.0 |
public function setOrder($order) {
$this->order = $order;
return $this;
} | Configure the order edge results are returned in.
@param string $order Order constant.
@return $this
@task config | setOrder | php | phorgeit/phorge | src/infrastructure/edges/query/PhabricatorEdgeQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/edges/query/PhabricatorEdgeQuery.php | Apache-2.0 |
public function needEdgeData($need) {
$this->needEdgeData = $need;
return $this;
} | When loading edges, also load edge data.
@param bool $need True to load edge data.
@return $this
@task config | needEdgeData | php | phorgeit/phorge | src/infrastructure/edges/query/PhabricatorEdgeQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/edges/query/PhabricatorEdgeQuery.php | Apache-2.0 |
public static function loadDestinationPHIDs($src_phid, $edge_type) {
$edges = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(array($src_phid))
->withEdgeTypes(array($edge_type))
->execute();
return array_keys($edges[$src_phid][$edge_type]);
} | Convenience method for loading destination PHIDs with one source and one
edge type. Equivalent to building a full query, but simplifies a common
use case.
@param string $src_phid Source PHID.
@param string $edge_type Edge type constant.
@return list<string> List of destination PHIDs. | loadDestinationPHIDs | php | phorgeit/phorge | src/infrastructure/edges/query/PhabricatorEdgeQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/edges/query/PhabricatorEdgeQuery.php | Apache-2.0 |
public static function loadSingleEdgeData($src_phid, $edge_type, $dest_phid) {
$edges = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(array($src_phid))
->withEdgeTypes(array($edge_type))
->withDestinationPHIDs(array($dest_phid))
->needEdgeData(true)
->execute();
if (isset($edges[$src_phid][$edge_type][$dest_phid]['data'])) {
return $edges[$src_phid][$edge_type][$dest_phid]['data'];
}
return null;
} | Convenience method for loading a single edge's metadata for
a given source, destination, and edge type. Returns null
if the edge does not exist or does not have metadata. Builds
and immediately executes a full query.
@param string $src_phid Source PHID.
@param string $edge_type Edge type constant.
@param string $dest_phid Destination PHID.
@return wild|null Edge annotation, or null. | loadSingleEdgeData | php | phorgeit/phorge | src/infrastructure/edges/query/PhabricatorEdgeQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/edges/query/PhabricatorEdgeQuery.php | Apache-2.0 |
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
$where = array();
if ($this->sourcePHIDs) {
$where[] = qsprintf(
$conn,
'edge.src IN (%Ls)',
$this->sourcePHIDs);
}
if ($this->edgeTypes) {
$where[] = qsprintf(
$conn,
'edge.type IN (%Ls)',
$this->edgeTypes);
}
if ($this->destPHIDs) {
// potentially complain if $this->edgeType was not set
$where[] = qsprintf(
$conn,
'edge.dst IN (%Ls)',
$this->destPHIDs);
}
return $this->formatWhereClause($conn, $where);
} | @task internal | buildWhereClause | php | phorgeit/phorge | src/infrastructure/edges/query/PhabricatorEdgeQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/edges/query/PhabricatorEdgeQuery.php | Apache-2.0 |
private function buildOrderClause(AphrontDatabaseConnection $conn) {
if ($this->order == self::ORDER_NEWEST_FIRST) {
return qsprintf($conn, 'ORDER BY edge.dateCreated DESC, edge.seq DESC');
} else {
return qsprintf($conn, 'ORDER BY edge.dateCreated ASC, edge.seq ASC');
}
} | @task internal | buildOrderClause | php | phorgeit/phorge | src/infrastructure/edges/query/PhabricatorEdgeQuery.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/edges/query/PhabricatorEdgeQuery.php | Apache-2.0 |
public static function getByConstant($const) {
$type = idx(self::getAllTypes(), $const);
if (!$type) {
throw new Exception(
pht('Unknown edge constant "%s"!', $const));
}
return $type;
} | @task load | getByConstant | php | phorgeit/phorge | src/infrastructure/edges/type/PhabricatorEdgeType.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/edges/type/PhabricatorEdgeType.php | Apache-2.0 |
public function removeEdge($src, $type, $dst) {
foreach ($this->buildEdgeSpecs($src, $type, $dst) as $spec) {
$this->remEdges[] = $spec;
}
return $this;
} | Remove an edge (possibly also removing its inverse). Changes take effect
when you call @{method:save}. If an edge does not exist, the removal
will be ignored. Edges are added after edges are removed, so the effect of
a remove plus an add is to overwrite.
@param string $src Source object PHID.
@param string $type Edge type constant.
@param string $dst Destination object PHID.
@return $this
@task edit | removeEdge | php | phorgeit/phorge | src/infrastructure/edges/editor/PhabricatorEdgeEditor.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/edges/editor/PhabricatorEdgeEditor.php | Apache-2.0 |
public function __concat($html) {
$clone = clone $this;
return $clone->appendHTML($html);
} | Requires http://pecl.php.net/operator. | __concat | php | phorgeit/phorge | src/infrastructure/markup/PhutilSafeHTML.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhutilSafeHTML.php | Apache-2.0 |
function phutil_safe_html($string) {
if ($string == '') {
return $string;
} else if ($string instanceof PhutilSafeHTML) {
return $string;
} else {
return new PhutilSafeHTML($string);
}
} | Mark string as safe for use in HTML. | phutil_safe_html | php | phorgeit/phorge | src/infrastructure/markup/render.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/render.php | Apache-2.0 |
function hsprintf($html /* , ... */) {
$args = func_get_args();
array_shift($args);
return new PhutilSafeHTML(
vsprintf($html, array_map('phutil_escape_html', $args)));
} | Format a HTML code. This function behaves like `sprintf()`, except that all
the normal conversions (like %s) will be properly escaped. | hsprintf | php | phorgeit/phorge | src/infrastructure/markup/render.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/render.php | Apache-2.0 |
public static function renderOneObject(
PhabricatorMarkupInterface $object,
$field,
PhabricatorUser $viewer,
$context_object = null) {
return id(new PhabricatorMarkupEngine())
->setViewer($viewer)
->setContextObject($context_object)
->addObject($object, $field)
->process()
->getOutput($object, $field);
} | Convenience method for pushing a single object through the markup
pipeline.
@param PhabricatorMarkupInterface $object The object to render.
@param string $field The field to render.
@param PhabricatorUser $viewer User viewing the markup.
@param object $context_object (optional) A context
object for policy checks.
@return string Marked up output.
@task markup | renderOneObject | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public function addObject(PhabricatorMarkupInterface $object, $field) {
$key = $this->getMarkupFieldKey($object, $field);
$this->objects[$key] = array(
'object' => $object,
'field' => $field,
);
return $this;
} | Queue an object for markup generation when @{method:process} is
called. You can retrieve the output later with @{method:getOutput}.
@param PhabricatorMarkupInterface $object The object to render.
@param string $field The field to render.
@return $this
@task markup | addObject | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public function getOutput(PhabricatorMarkupInterface $object, $field) {
$key = $this->getMarkupFieldKey($object, $field);
$this->requireKeyProcessed($key);
return $this->objects[$key]['output'];
} | Get the output of markup processing for a field queued with
@{method:addObject}. Before you can call this method, you must call
@{method:process}.
@param PhabricatorMarkupInterface $object The object to retrieve.
@param string $field The field to retrieve.
@return string Processed output.
@task markup | getOutput | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public function getEngineMetadata(
PhabricatorMarkupInterface $object,
$field,
$metadata_key,
$default = null) {
$key = $this->getMarkupFieldKey($object, $field);
$this->requireKeyProcessed($key);
return idx($this->engineCaches[$key]['metadata'], $metadata_key, $default);
} | Retrieve engine metadata for a given field.
@param PhabricatorMarkupInterface $object The object to retrieve.
@param string $field The field to retrieve.
@param string $metadata_key The engine metadata field
to retrieve.
@param wild $default (optional) Default value.
@task markup | getEngineMetadata | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
private function requireKeyProcessed($key) {
if (empty($this->objects[$key])) {
throw new Exception(
pht(
"Call %s before using results (key = '%s').",
'addObject()',
$key));
}
if (!isset($this->objects[$key]['output'])) {
throw new PhutilInvalidStateException('process');
}
} | @task markup | requireKeyProcessed | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
private function getMarkupFieldKey(
PhabricatorMarkupInterface $object,
$field) {
static $custom;
if ($custom === null) {
$custom = array_merge(
self::loadCustomInlineRules(),
self::loadCustomBlockRules());
$custom = mpull($custom, 'getRuleVersion', null);
ksort($custom);
$custom = PhabricatorHash::digestForIndex(serialize($custom));
}
return $object->getMarkupFieldKey($field).'@'.$this->version.'@'.$custom;
} | @task markup | getMarkupFieldKey | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
} | Set the viewing user. Used to implement object permissions.
@param PhabricatorUser $viewer The viewing user.
@return $this
@task markup | setViewer | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public function setContextObject($object) {
$this->contextObject = $object;
return $this;
} | Set the context object. Used to implement object permissions.
@param $object The object in which context this remarkup is used.
@return $this
@task markup | setContextObject | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public static function newManiphestMarkupEngine() {
return self::newMarkupEngine(array(
));
} | @task engine | newManiphestMarkupEngine | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public static function newPhrictionMarkupEngine() {
return self::newMarkupEngine(array(
'header.generate-toc' => true,
));
} | @task engine | newPhrictionMarkupEngine | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public static function newPhameMarkupEngine() {
return self::newMarkupEngine(
array(
'macros' => false,
'uri.full' => true,
'uri.same-window' => true,
'uri.base' => PhabricatorEnv::getURI('/'),
));
} | @task engine | newPhameMarkupEngine | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public static function newFeedMarkupEngine() {
return self::newMarkupEngine(
array(
'macros' => false,
'youtube' => false,
));
} | @task engine | newFeedMarkupEngine | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public static function newCalendarMarkupEngine() {
return self::newMarkupEngine(array(
));
} | @task engine | newCalendarMarkupEngine | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public static function getEngine($ruleset = 'default') {
static $engines = array();
if (isset($engines[$ruleset])) {
return $engines[$ruleset];
}
$engine = null;
switch ($ruleset) {
case 'default':
$engine = self::newMarkupEngine(array());
break;
case 'feed':
$engine = self::newMarkupEngine(array());
$engine->setConfig('autoplay.disable', true);
break;
case 'nolinebreaks':
$engine = self::newMarkupEngine(array());
$engine->setConfig('preserve-linebreaks', false);
break;
case 'diffusion-readme':
$engine = self::newMarkupEngine(array());
$engine->setConfig('preserve-linebreaks', false);
$engine->setConfig('header.generate-toc', true);
break;
case 'diviner':
$engine = self::newMarkupEngine(array());
$engine->setConfig('preserve-linebreaks', false);
// $engine->setConfig('diviner.renderer', new DivinerDefaultRenderer());
$engine->setConfig('header.generate-toc', true);
break;
case 'extract':
// Engine used for reference/edge extraction. Turn off anything which
// is slow and doesn't change reference extraction.
$engine = self::newMarkupEngine(array());
$engine->setConfig('pygments.enabled', false);
break;
default:
throw new Exception(pht('Unknown engine ruleset: %s!', $ruleset));
}
$engines[$ruleset] = $engine;
return $engine;
} | @task engine | getEngine | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
private static function getMarkupEngineDefaultConfiguration() {
return array(
'pygments' => PhabricatorEnv::getEnvConfig('pygments.enabled'),
'youtube' => PhabricatorEnv::getEnvConfig(
'remarkup.enable-embedded-youtube'),
'differential.diff' => null,
'header.generate-toc' => false,
'macros' => true,
'uri.allowed-protocols' => PhabricatorEnv::getEnvConfig(
'uri.allowed-protocols'),
'uri.full' => false,
'syntax-highlighter.engine' => PhabricatorEnv::getEnvConfig(
'syntax-highlighter.engine'),
'preserve-linebreaks' => true,
);
} | @task engine | getMarkupEngineDefaultConfiguration | php | phorgeit/phorge | src/infrastructure/markup/PhabricatorMarkupEngine.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/PhabricatorMarkupEngine.php | Apache-2.0 |
public function markupContent($content, array $argv) {
$map = self::getFigletMap();
$font = idx($argv, 'font');
$font = phutil_utf8_strtolower($font);
if (empty($map[$font])) {
$font = 'standard';
}
$root = dirname(phutil_get_library_root('phabricator'));
require_once $root.'/externals/pear-figlet/Text/Figlet.php';
$figlet = new Text_Figlet();
$figlet->loadFont($map[$font]);
$result = $figlet->lineEcho($content);
$engine = $this->getEngine();
if ($engine->isTextMode()) {
return $result;
}
if ($engine->isHTMLMailMode()) {
return phutil_tag('pre', array(), $result);
}
return phutil_tag(
'div',
array(
'class' => 'PhabricatorMonospaced remarkup-figlet',
),
$result);
} | @phutil-external-symbol class Text_Figlet | markupContent | php | phorgeit/phorge | src/infrastructure/markup/interpreter/PhabricatorRemarkupFigletBlockInterpreter.php | https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/interpreter/PhabricatorRemarkupFigletBlockInterpreter.php | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.