3 final class AlmanacNamespace
6 PhabricatorPolicyInterface
,
7 PhabricatorApplicationTransactionInterface
,
8 PhabricatorProjectInterface
,
9 PhabricatorDestructibleInterface
,
10 PhabricatorNgramsInterface
,
11 PhabricatorConduitResultInterface
{
15 protected $viewPolicy;
16 protected $editPolicy;
18 public static function initializeNewNamespace() {
20 ->setViewPolicy(PhabricatorPolicies
::POLICY_USER
)
21 ->setEditPolicy(PhabricatorPolicies
::POLICY_ADMIN
);
24 protected function getConfiguration() {
26 self
::CONFIG_AUX_PHID
=> true,
27 self
::CONFIG_COLUMN_SCHEMA
=> array(
29 'nameIndex' => 'bytes12',
31 self
::CONFIG_KEY_SCHEMA
=> array(
32 'key_nameindex' => array(
33 'columns' => array('nameIndex'),
37 'columns' => array('name'),
40 ) + parent
::getConfiguration();
43 public function getPHIDType() {
44 return AlmanacNamespacePHIDType
::TYPECONST
;
47 public function save() {
48 AlmanacNames
::validateName($this->getName());
50 $this->nameIndex
= PhabricatorHash
::digestForIndex($this->getName());
52 return parent
::save();
55 public function getURI() {
57 '/almanac/namespace/view/%s/',
61 public function getNameLength() {
62 return strlen($this->getName());
66 * Load the namespace which prevents use of an Almanac name, if one exists.
68 public static function loadRestrictedNamespace(
69 PhabricatorUser
$viewer,
72 // For a name like "x.y.z", produce a list of controlling namespaces like
73 // ("z", "y.x", "x.y.z").
75 $parts = explode('.', $name);
76 for ($ii = 0; $ii < count($parts); $ii++
) {
77 $names[] = implode('.', array_slice($parts, -($ii +
1)));
80 // Load all the possible controlling namespaces.
81 $namespaces = id(new AlmanacNamespaceQuery())
82 ->setViewer(PhabricatorUser
::getOmnipotentUser())
89 // Find the "nearest" (longest) namespace that exists. If both
90 // "sub.domain.com" and "domain.com" exist, we only care about the policy
92 $namespaces = msort($namespaces, 'getNameLength');
93 $namespace = last($namespaces);
95 $can_edit = PhabricatorPolicyFilter
::hasCapability(
98 PhabricatorPolicyCapability
::CAN_EDIT
);
107 /* -( PhabricatorPolicyInterface )----------------------------------------- */
110 public function getCapabilities() {
112 PhabricatorPolicyCapability
::CAN_VIEW
,
113 PhabricatorPolicyCapability
::CAN_EDIT
,
117 public function getPolicy($capability) {
118 switch ($capability) {
119 case PhabricatorPolicyCapability
::CAN_VIEW
:
120 return $this->getViewPolicy();
121 case PhabricatorPolicyCapability
::CAN_EDIT
:
122 return $this->getEditPolicy();
126 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
131 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
134 public function getApplicationTransactionEditor() {
135 return new AlmanacNamespaceEditor();
138 public function getApplicationTransactionTemplate() {
139 return new AlmanacNamespaceTransaction();
143 /* -( PhabricatorDestructibleInterface )----------------------------------- */
146 public function destroyObjectPermanently(
147 PhabricatorDestructionEngine
$engine) {
152 /* -( PhabricatorNgramsInterface )----------------------------------------- */
155 public function newNgrams() {
157 id(new AlmanacNamespaceNameNgrams())
158 ->setValue($this->getName()),
163 /* -( PhabricatorConduitResultInterface )---------------------------------- */
166 public function getFieldSpecificationsForConduit() {
168 id(new PhabricatorConduitSearchFieldSpecification())
171 ->setDescription(pht('The name of the namespace.')),
175 public function getFieldValuesForConduit() {
177 'name' => $this->getName(),
181 public function getConduitSearchAttachments() {