/** * Get the number of directory matches between this path specification and * some real path. */ public function getPathMatchStrength($path) { $this_path = $this->getPath(); if ($this_path === '/') { // The root path "/" just matches everything with strength 1. return 1; } $self_fragments = PhabricatorOwnersPackage::splitPath($this_path); $path_fragments = PhabricatorOwnersPackage::splitPath($path); $self_count = count($self_fragments); $path_count = count($path_fragments); if ($self_count > $path_count) { // If this path is longer (and therefor more specific) than the target // path, we don't match it at all. return 0; } for ($ii = 0; $ii < $self_count; $ii++) { if ($self_fragments[$ii] != $path_fragments[$ii]) { return 0; } } return $self_count; }
private function getFragmentsForPaths(array $paths) { $fragments = array(); foreach ($paths as $path) { foreach (PhabricatorOwnersPackage::splitPath($path) as $fragment) { $fragments[$fragment] = $fragment; } } return $fragments; }
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->phids !== null) { $where[] = qsprintf($conn, 'p.phid IN (%Ls)', $this->phids); } if ($this->ids !== null) { $where[] = qsprintf($conn, 'p.id IN (%Ld)', $this->ids); } if ($this->repositoryPHIDs !== null) { $where[] = qsprintf($conn, 'rpath.repositoryPHID IN (%Ls)', $this->repositoryPHIDs); } if ($this->ownerPHIDs !== null) { $base_phids = $this->ownerPHIDs; $projects = id(new PhabricatorProjectQuery())->setViewer($this->getViewer())->withMemberPHIDs($base_phids)->execute(); $project_phids = mpull($projects, 'getPHID'); $all_phids = array_merge($base_phids, $project_phids); $where[] = qsprintf($conn, 'o.userPHID IN (%Ls)', $all_phids); } if (strlen($this->namePrefix)) { // NOTE: This is a hacky mess, but this column is currently case // sensitive and unique. $where[] = qsprintf($conn, 'LOWER(p.name) LIKE %>', phutil_utf8_strtolower($this->namePrefix)); } if ($this->controlMap) { $clauses = array(); foreach ($this->controlMap as $repository_phid => $paths) { $fragments = array(); foreach ($paths as $path) { foreach (PhabricatorOwnersPackage::splitPath($path) as $fragment) { $fragments[$fragment] = $fragment; } } $clauses[] = qsprintf($conn, '(rpath.repositoryPHID = %s AND rpath.path IN (%Ls))', $repository_phid, $fragments); } $where[] = implode(' OR ', $clauses); } return $where; }