[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class AlmanacService 4 extends AlmanacDAO 5 implements 6 PhabricatorPolicyInterface, 7 PhabricatorCustomFieldInterface, 8 PhabricatorApplicationTransactionInterface, 9 PhabricatorProjectInterface, 10 AlmanacPropertyInterface { 11 12 protected $name; 13 protected $nameIndex; 14 protected $mailKey; 15 protected $viewPolicy; 16 protected $editPolicy; 17 18 private $customFields = self::ATTACHABLE; 19 private $almanacProperties = self::ATTACHABLE; 20 21 public static function initializeNewService() { 22 return id(new AlmanacService()) 23 ->setViewPolicy(PhabricatorPolicies::POLICY_USER) 24 ->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN) 25 ->attachAlmanacProperties(array()); 26 } 27 28 public function getConfiguration() { 29 return array( 30 self::CONFIG_AUX_PHID => true, 31 self::CONFIG_COLUMN_SCHEMA => array( 32 'name' => 'text128', 33 'nameIndex' => 'bytes12', 34 'mailKey' => 'bytes20', 35 ), 36 self::CONFIG_KEY_SCHEMA => array( 37 'key_name' => array( 38 'columns' => array('nameIndex'), 39 'unique' => true, 40 ), 41 'key_nametext' => array( 42 'columns' => array('name'), 43 ), 44 ), 45 ) + parent::getConfiguration(); 46 } 47 48 public function generatePHID() { 49 return PhabricatorPHID::generateNewPHID(AlmanacServicePHIDType::TYPECONST); 50 } 51 52 public function save() { 53 AlmanacNames::validateServiceOrDeviceName($this->getName()); 54 55 $this->nameIndex = PhabricatorHash::digestForIndex($this->getName()); 56 57 if (!$this->mailKey) { 58 $this->mailKey = Filesystem::readRandomCharacters(20); 59 } 60 61 return parent::save(); 62 } 63 64 public function getURI() { 65 return '/almanac/service/view/'.$this->getName().'/'; 66 } 67 68 69 /* -( AlmanacPropertyInterface )------------------------------------------- */ 70 71 72 public function attachAlmanacProperties(array $properties) { 73 assert_instances_of($properties, 'AlmanacProperty'); 74 $this->almanacProperties = mpull($properties, null, 'getFieldName'); 75 return $this; 76 } 77 78 public function getAlmanacProperties() { 79 return $this->assertAttached($this->almanacProperties); 80 } 81 82 public function hasAlmanacProperty($key) { 83 $this->assertAttached($this->almanacProperties); 84 return isset($this->almanacProperties[$key]); 85 } 86 87 public function getAlmanacProperty($key) { 88 return $this->assertAttachedKey($this->almanacProperties, $key); 89 } 90 91 public function getAlmanacPropertyValue($key, $default = null) { 92 if ($this->hasAlmanacProperty($key)) { 93 return $this->getAlmanacProperty($key)->getFieldValue(); 94 } else { 95 return $default; 96 } 97 } 98 99 100 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 101 102 103 public function getCapabilities() { 104 return array( 105 PhabricatorPolicyCapability::CAN_VIEW, 106 PhabricatorPolicyCapability::CAN_EDIT, 107 ); 108 } 109 110 public function getPolicy($capability) { 111 switch ($capability) { 112 case PhabricatorPolicyCapability::CAN_VIEW: 113 return $this->getViewPolicy(); 114 case PhabricatorPolicyCapability::CAN_EDIT: 115 return $this->getEditPolicy(); 116 } 117 } 118 119 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 120 return false; 121 } 122 123 public function describeAutomaticCapability($capability) { 124 return null; 125 } 126 127 128 /* -( PhabricatorCustomFieldInterface )------------------------------------ */ 129 130 131 public function getCustomFieldSpecificationForRole($role) { 132 return array(); 133 } 134 135 public function getCustomFieldBaseClass() { 136 return 'AlmanacCustomField'; 137 } 138 139 public function getCustomFields() { 140 return $this->assertAttached($this->customFields); 141 } 142 143 public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) { 144 $this->customFields = $fields; 145 return $this; 146 } 147 148 149 /* -( PhabricatorApplicationTransactionInterface )------------------------- */ 150 151 152 public function getApplicationTransactionEditor() { 153 return new AlmanacServiceEditor(); 154 } 155 156 public function getApplicationTransactionObject() { 157 return $this; 158 } 159 160 public function getApplicationTransactionTemplate() { 161 return new AlmanacServiceTransaction(); 162 } 163 164 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |