3 final class PhabricatorPackagesVersion
4 extends PhabricatorPackagesDAO
6 PhabricatorPolicyInterface
,
7 PhabricatorExtendedPolicyInterface
,
8 PhabricatorApplicationTransactionInterface
,
9 PhabricatorDestructibleInterface
,
10 PhabricatorSubscribableInterface
,
11 PhabricatorProjectInterface
,
12 PhabricatorConduitResultInterface
,
13 PhabricatorNgramsInterface
{
16 protected $packagePHID;
20 public static function initializeNewVersion(PhabricatorUser
$actor) {
21 return id(new self());
24 protected function getConfiguration() {
26 self
::CONFIG_AUX_PHID
=> true,
27 self
::CONFIG_COLUMN_SCHEMA
=> array(
30 self
::CONFIG_KEY_SCHEMA
=> array(
31 'key_package' => array(
32 'columns' => array('packagePHID', 'name'),
36 ) + parent
::getConfiguration();
39 public function generatePHID() {
40 return PhabricatorPHID
::generateNewPHID(
41 PhabricatorPackagesVersionPHIDType
::TYPECONST
);
44 public function getURI() {
45 $package = $this->getPackage();
46 $full_key = $package->getFullKey();
47 $name = $this->getName();
49 return "/package/{$full_key}/{$name}/";
52 public function attachPackage(PhabricatorPackagesPackage
$package) {
53 $this->package
= $package;
57 public function getPackage() {
58 return $this->assertAttached($this->package
);
61 public static function assertValidVersionName($value) {
62 $length = phutil_utf8_strlen($value);
66 'Version name "%s" is not valid: version names are required.',
71 if ($length > $max_length) {
74 'Version name "%s" is not valid: version names must not be '.
75 'more than %s characters long.',
77 new PhutilNumber($max_length)));
80 if (!preg_match('/^[A-Za-z0-9.-]+\z/', $value)) {
83 'Version name "%s" is not valid: version names may only contain '.
84 'latin letters, digits, periods, and hyphens.',
88 if (preg_match('/^[.-]|[.-]$/', $value)) {
91 'Version name "%s" is not valid: version names may not start or '.
92 'end with a period or hyphen.',
98 /* -( PhabricatorSubscribableInterface )----------------------------------- */
101 public function isAutomaticallySubscribed($phid) {
106 /* -( Policy Interface )--------------------------------------------------- */
109 public function getCapabilities() {
111 PhabricatorPolicyCapability
::CAN_VIEW
,
112 PhabricatorPolicyCapability
::CAN_EDIT
,
116 public function getPolicy($capability) {
117 switch ($capability) {
118 case PhabricatorPolicyCapability
::CAN_VIEW
:
119 return PhabricatorPolicies
::getMostOpenPolicy();
120 case PhabricatorPolicyCapability
::CAN_EDIT
:
121 return PhabricatorPolicies
::POLICY_USER
;
125 public function hasAutomaticCapability($capability, PhabricatorUser
$user) {
130 /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
133 public function getExtendedPolicy($capability, PhabricatorUser
$viewer) {
143 /* -( PhabricatorDestructibleInterface )----------------------------------- */
146 public function destroyObjectPermanently(
147 PhabricatorDestructionEngine
$engine) {
152 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
155 public function getApplicationTransactionEditor() {
156 return new PhabricatorPackagesVersionEditor();
159 public function getApplicationTransactionTemplate() {
160 return new PhabricatorPackagesVersionTransaction();
164 /* -( PhabricatorNgramsInterface )----------------------------------------- */
167 public function newNgrams() {
169 id(new PhabricatorPackagesVersionNameNgrams())
170 ->setValue($this->getName()),
175 /* -( PhabricatorConduitResultInterface )---------------------------------- */
178 public function getFieldSpecificationsForConduit() {
180 id(new PhabricatorConduitSearchFieldSpecification())
183 ->setDescription(pht('The name of the version.')),
187 public function getFieldValuesForConduit() {
189 'name' => $this->getName(),
193 public function getConduitSearchAttachments() {