Changeset View
Changeset View
Standalone View
Standalone View
src/applications/owners/storage/PhabricatorOwnersPath.php
<?php | <?php | ||||
final class PhabricatorOwnersPath extends PhabricatorOwnersDAO { | final class PhabricatorOwnersPath extends PhabricatorOwnersDAO { | ||||
protected $packageID; | protected $packageID; | ||||
protected $repositoryPHID; | protected $repositoryPHID; | ||||
protected $path; | protected $path; | ||||
protected $excluded; | protected $excluded; | ||||
private $fragments; | |||||
private $fragmentCount; | |||||
protected function getConfiguration() { | protected function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_TIMESTAMPS => false, | self::CONFIG_TIMESTAMPS => false, | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'path' => 'text255', | 'path' => 'text255', | ||||
'excluded' => 'bool', | 'excluded' => 'bool', | ||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | final class PhabricatorOwnersPath extends PhabricatorOwnersDAO { | ||||
public static function isRefInSet(array $ref, array $set) { | public static function isRefInSet(array $ref, array $set) { | ||||
return isset($set[$ref['repositoryPHID']][$ref['path']][$ref['excluded']]); | return isset($set[$ref['repositoryPHID']][$ref['path']][$ref['excluded']]); | ||||
} | } | ||||
/** | /** | ||||
* Get the number of directory matches between this path specification and | * Get the number of directory matches between this path specification and | ||||
* some real path. | * some real path. | ||||
*/ | */ | ||||
public function getPathMatchStrength($path) { | public function getPathMatchStrength($path_fragments, $path_count) { | ||||
$this_path = $this->getPath(); | $this_path = $this->path; | ||||
if ($this_path === '/') { | if ($this_path === '/') { | ||||
// The root path "/" just matches everything with strength 1. | // The root path "/" just matches everything with strength 1. | ||||
return 1; | return 1; | ||||
} | } | ||||
$self_fragments = PhabricatorOwnersPackage::splitPath($this_path); | if ($this->fragments === null) { | ||||
$path_fragments = PhabricatorOwnersPackage::splitPath($path); | $this->fragments = PhabricatorOwnersPackage::splitPath($this_path); | ||||
$this->fragmentCount = count($this->fragments); | |||||
} | |||||
$self_count = count($self_fragments); | $self_fragments = $this->fragments; | ||||
$path_count = count($path_fragments); | $self_count = $this->fragmentCount; | ||||
if ($self_count > $path_count) { | if ($self_count > $path_count) { | ||||
// If this path is longer (and therefore more specific) than the target | // If this path is longer (and therefore more specific) than the target | ||||
// path, we don't match it at all. | // path, we don't match it at all. | ||||
return 0; | return 0; | ||||
} | } | ||||
for ($ii = 0; $ii < $self_count; $ii++) { | for ($ii = 0; $ii < $self_count; $ii++) { | ||||
if ($self_fragments[$ii] != $path_fragments[$ii]) { | if ($self_fragments[$ii] != $path_fragments[$ii]) { | ||||
return 0; | return 0; | ||||
} | } | ||||
} | } | ||||
return $self_count; | return $self_count; | ||||
} | } | ||||
} | } |