Changeset View
Changeset View
Standalone View
Standalone View
src/applications/packages/storage/PhabricatorPackagesVersion.php
- This file was copied from src/applications/packages/storage/PhabricatorPackagesPackage.php.
<?php | <?php | ||||
final class PhabricatorPackagesPackage | final class PhabricatorPackagesVersion | ||||
extends PhabricatorPackagesDAO | extends PhabricatorPackagesDAO | ||||
implements | implements | ||||
PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
PhabricatorExtendedPolicyInterface, | |||||
PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
PhabricatorDestructibleInterface, | PhabricatorDestructibleInterface, | ||||
PhabricatorSubscribableInterface, | PhabricatorSubscribableInterface, | ||||
PhabricatorProjectInterface, | PhabricatorProjectInterface, | ||||
PhabricatorConduitResultInterface { | PhabricatorConduitResultInterface { | ||||
protected $name; | protected $name; | ||||
protected $publisherPHID; | protected $packagePHID; | ||||
protected $packageKey; | |||||
protected $viewPolicy; | |||||
protected $editPolicy; | |||||
private $publisher = self::ATTACHABLE; | private $package; | ||||
public static function initializeNewPackage(PhabricatorUser $actor) { | public static function initializeNewVersion(PhabricatorUser $actor) { | ||||
return id(new self()); | return id(new self()); | ||||
} | } | ||||
protected function getConfiguration() { | protected function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'name' => 'text64', | 'name' => 'sort64', | ||||
'packageKey' => 'sort64', | |||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_package' => array( | 'key_package' => array( | ||||
'columns' => array('publisherPHID', 'packageKey'), | 'columns' => array('packagePHID', 'name'), | ||||
'unique' => true, | 'unique' => true, | ||||
), | ), | ||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function generatePHID() { | public function generatePHID() { | ||||
return PhabricatorPHID::generateNewPHID( | return PhabricatorPHID::generateNewPHID( | ||||
PhabricatorPackagesPackagePHIDType::TYPECONST); | PhabricatorPackagesVersionPHIDType::TYPECONST); | ||||
} | } | ||||
public function getURI() { | public function getURI() { | ||||
$full_key = $this->getFullKey(); | $package = $this->getPackage(); | ||||
return "/package/{$full_key}/"; | $full_key = $package->getFullKey(); | ||||
} | $name = $this->getName(); | ||||
public function getFullKey() { | return "/package/{$full_key}/{$name}/"; | ||||
$publisher = $this->getPublisher(); | |||||
$publisher_key = $publisher->getPublisherKey(); | |||||
$package_key = $this->getPackageKey(); | |||||
return "{$publisher_key}/{$package_key}"; | |||||
} | } | ||||
public function attachPublisher(PhabricatorPackagesPublisher $publisher) { | public function attachPackage(PhabricatorPackagesPackage $package) { | ||||
$this->publisher = $publisher; | $this->package = $package; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getPublisher() { | public function getPackage() { | ||||
return $this->assertAttached($this->publisher); | return $this->assertAttached($this->package); | ||||
} | } | ||||
public static function assertValidPackageName($value) { | public static function assertValidVersionName($value) { | ||||
$length = phutil_utf8_strlen($value); | $length = phutil_utf8_strlen($value); | ||||
if (!$length) { | if (!$length) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Package name "%s" is not valid: package names are required.', | 'Version name "%s" is not valid: version names are required.', | ||||
$value)); | $value)); | ||||
} | } | ||||
$max_length = 64; | $max_length = 64; | ||||
if ($length > $max_length) { | if ($length > $max_length) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Package name "%s" is not valid: package names must not be '. | 'Version name "%s" is not valid: version names must not be '. | ||||
'more than %s characters long.', | 'more than %s characters long.', | ||||
$value, | $value, | ||||
new PhutilNumber($max_length))); | new PhutilNumber($max_length))); | ||||
} | } | ||||
} | |||||
public static function assertValidPackageKey($value) { | if (!preg_match('/^[A-Za-z0-9.-]+\z/', $value)) { | ||||
$length = phutil_utf8_strlen($value); | |||||
if (!$length) { | |||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Package key "%s" is not valid: package keys are required.', | 'Version name "%s" is not valid: version names may only contain '. | ||||
'latin letters, digits, periods, and hyphens.', | |||||
$value)); | $value)); | ||||
} | } | ||||
$max_length = 64; | if (preg_match('/^[.-]|[.-]$/', $value)) { | ||||
if ($length > $max_length) { | |||||
throw new Exception( | |||||
pht( | |||||
'Package key "%s" is not valid: package keys must not be '. | |||||
'more than %s characters long.', | |||||
$value, | |||||
new PhutilNumber($max_length))); | |||||
} | |||||
if (!preg_match('/^[a-z]+\z/', $value)) { | |||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Package key "%s" is not valid: package keys may only contain '. | 'Version name "%s" is not valid: version names may not start or '. | ||||
'lowercase latin letters.', | 'end with a period or hyphen.', | ||||
$value)); | $value)); | ||||
} | } | ||||
} | } | ||||
/* -( PhabricatorSubscribableInterface )----------------------------------- */ | /* -( PhabricatorSubscribableInterface )----------------------------------- */ | ||||
Show All 10 Lines | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
); | ); | ||||
} | } | ||||
public function getPolicy($capability) { | public function getPolicy($capability) { | ||||
switch ($capability) { | switch ($capability) { | ||||
case PhabricatorPolicyCapability::CAN_VIEW: | case PhabricatorPolicyCapability::CAN_VIEW: | ||||
return $this->getViewPolicy(); | return PhabricatorPolicies::getMostOpenPolicy(); | ||||
case PhabricatorPolicyCapability::CAN_EDIT: | case PhabricatorPolicyCapability::CAN_EDIT: | ||||
return $this->getEditPolicy(); | return PhabricatorPolicies::POLICY_USER; | ||||
} | } | ||||
} | } | ||||
public function hasAutomaticCapability($capability, PhabricatorUser $user) { | public function hasAutomaticCapability($capability, PhabricatorUser $user) { | ||||
return false; | return false; | ||||
} | } | ||||
public function describeAutomaticCapability($capability) { | public function describeAutomaticCapability($capability) { | ||||
return null; | return null; | ||||
} | } | ||||
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */ | |||||
public function getExtendedPolicy($capability, PhabricatorUser $viewer) { | |||||
return array( | |||||
array( | |||||
$this->getPackage(), | |||||
$capability, | |||||
), | |||||
); | |||||
} | |||||
/* -( PhabricatorDestructibleInterface )----------------------------------- */ | /* -( PhabricatorDestructibleInterface )----------------------------------- */ | ||||
public function destroyObjectPermanently( | public function destroyObjectPermanently( | ||||
PhabricatorDestructionEngine $engine) { | PhabricatorDestructionEngine $engine) { | ||||
$this->delete(); | $this->delete(); | ||||
} | } | ||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */ | /* -( PhabricatorApplicationTransactionInterface )------------------------- */ | ||||
public function getApplicationTransactionEditor() { | public function getApplicationTransactionEditor() { | ||||
return new PhabricatorPackagesPackageEditor(); | return new PhabricatorPackagesVersionEditor(); | ||||
} | } | ||||
public function getApplicationTransactionObject() { | public function getApplicationTransactionObject() { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getApplicationTransactionTemplate() { | public function getApplicationTransactionTemplate() { | ||||
return new PhabricatorPackagesPackageTransaction(); | return new PhabricatorPackagesVersionTransaction(); | ||||
} | } | ||||
public function willRenderTimeline( | public function willRenderTimeline( | ||||
PhabricatorApplicationTransactionView $timeline, | PhabricatorApplicationTransactionView $timeline, | ||||
AphrontRequest $request) { | AphrontRequest $request) { | ||||
return $timeline; | return $timeline; | ||||
} | } | ||||
/* -( PhabricatorConduitResultInterface )---------------------------------- */ | /* -( PhabricatorConduitResultInterface )---------------------------------- */ | ||||
public function getFieldSpecificationsForConduit() { | public function getFieldSpecificationsForConduit() { | ||||
return array( | return array( | ||||
id(new PhabricatorConduitSearchFieldSpecification()) | id(new PhabricatorConduitSearchFieldSpecification()) | ||||
->setKey('name') | ->setKey('name') | ||||
->setType('string') | ->setType('string') | ||||
->setDescription(pht('The name of the package.')), | ->setDescription(pht('The name of the version.')), | ||||
id(new PhabricatorConduitSearchFieldSpecification()) | |||||
->setKey('packageKey') | |||||
->setType('string') | |||||
->setDescription(pht('The unique key of the package.')), | |||||
); | ); | ||||
} | } | ||||
public function getFieldValuesForConduit() { | public function getFieldValuesForConduit() { | ||||
$publisher = $this->getPublisher(); | |||||
$publisher_map = array( | |||||
'id' => (int)$publisher->getID(), | |||||
'phid' => $publisher->getPHID(), | |||||
'name' => $publisher->getName(), | |||||
'publisherKey' => $publisher->getPublisherKey(), | |||||
); | |||||
return array( | return array( | ||||
'name' => $this->getName(), | 'name' => $this->getName(), | ||||
'packageKey' => $this->getPackageKey(), | |||||
'fullKey' => $this->getFullKey(), | |||||
'publisher' => $publisher_map, | |||||
); | ); | ||||
} | } | ||||
public function getConduitSearchAttachments() { | public function getConduitSearchAttachments() { | ||||
return array(); | return array(); | ||||
} | } | ||||
} | } |