Page MenuHomePhabricator

final class PhabricatorEdgeQuery
Phabricator Technical Documentation (Edges)

Load object edges created by PhabricatorEdgeEditor.

Querying Edges
$src  = $earth_phid;
$type = PhabricatorEdgeConfig::TYPE_BODY_HAS_SATELLITE;

// Load the earth's satellites.
$satellite_edges = id(new PhabricatorEdgeQuery())
  ->withSourcePHIDs(array($src))
  ->withEdgeTypes(array($type))
  ->execute();

For more information on edges, see Using Edges.

Tasks

Formatting Query Clauses

Configuring the Query

  • public function withSourcePHIDs($source_phids) — Find edges originating at one or more source PHIDs. You MUST provide this to execute an edge query.
  • public function withEdgeTypes($types) — Find edges of specific types.
  • public function setOrder($order) — Configure the order edge results are returned in.
  • public function needEdgeData($need) — When loading edges, also load edge data.

Executing the Query

  • public function execute() — Load specified edges.

Internal

Other Methods

  • public function withDestinationPHIDs($dest_phids) — Find edges terminating at one or more destination PHIDs.
  • public static function loadDestinationPHIDs($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.
  • public static function loadSingleEdgeData($src_phid, $edge_type, $dest_phid) — 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.
  • public function getDestinationPHIDs($src_phids, $types) — Convenience function for selecting edge destination PHIDs after calling execute().

Methods

public function execute()

Load specified edges.

Return
wild

protected function formatWhereClause($conn, $parts)
Inherited

This method is not documented.
Parameters
AphrontDatabaseConnection$conn
array$parts
Return
wild

protected function formatSelectClause($conn, $parts)
Inherited

This method is not documented.
Parameters
AphrontDatabaseConnection$conn
array$parts
Return
wild

protected function formatJoinClause($conn, $parts)
Inherited

This method is not documented.
Parameters
AphrontDatabaseConnection$conn
array$parts
Return
wild

protected function formatHavingClause($conn, $parts)
Inherited

This method is not documented.
Parameters
AphrontDatabaseConnection$conn
array$parts
Return
wild

private function flattenSubclause($parts)
Inherited

This method is not documented.
Parameters
array$parts
Return
wild

public function withSourcePHIDs($source_phids)

Find edges originating at one or more source PHIDs. You MUST provide this to execute an edge query.

Parameters
list$source_phidsList of source PHIDs.
Return
this

public function withDestinationPHIDs($dest_phids)

Find edges terminating at one or more destination PHIDs.

Parameters
list$dest_phidsList of destination PHIDs.
Return
this

public function withEdgeTypes($types)

Find edges of specific types.

Parameters
list$typesList of PhabricatorEdgeConfig type constants.
Return
this

public function setOrder($order)

Configure the order edge results are returned in.

Parameters
const$orderOrder constant.
Return
this

public function needEdgeData($need)

When loading edges, also load edge data.

Parameters
bool$needTrue to load edge data.
Return
this

public static function loadDestinationPHIDs($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.

Parameters
phid$src_phidSource PHID.
const$edge_typeEdge type.
Return
list<phid>List of destination PHIDs.

public static function loadSingleEdgeData($src_phid, $edge_type, $dest_phid)

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.

Parameters
phid$src_phidSource PHID.
const$edge_typeEdge type.
phid$dest_phidDestination PHID.
Return
wildEdge annotation (or null).

public function getDestinationPHIDs($src_phids, $types)

Convenience function for selecting edge destination PHIDs after calling execute().

Returns a flat list of PHIDs matching the provided source PHID and type filters. By default, the filters are empty so all PHIDs will be returned. For example, if you're doing a batch query from several sources, you might write code like this:

$query = new PhabricatorEdgeQuery();
$query->setViewer($viewer);
$query->withSourcePHIDs(mpull($objects, 'getPHID'));
$query->withEdgeTypes(array($some_type));
$query->execute();

// Gets all of the destinations.
$all_phids = $query->getDestinationPHIDs();
$handles = id(new PhabricatorHandleQuery())
  ->setViewer($viewer)
  ->withPHIDs($all_phids)
  ->execute();

foreach ($objects as $object) {
  // Get all of the destinations for the given object.
  $dst_phids = $query->getDestinationPHIDs(array($object->getPHID()));
  $object->attachHandles(array_select_keys($handles, $dst_phids));
}
Parameters
list?$src_phidsList of PHIDs to select, or empty to select all.
list?$typesList of edge types to select, or empty to select all.
Return
list<phid>List of matching destination PHIDs.

protected function buildWhereClause($conn)

This method is not documented.
Parameters
AphrontDatabaseConnection$conn
Return
wild

private function buildOrderClause($conn)

This method is not documented.
Parameters
AphrontDatabaseConnection$conn
Return
wild