1<?php 2 3abstract class ArcanistHardpointObject 4 extends Phobject { 5 6 private $hardpointList; 7 8 public function __clone() { 9 if ($this->hardpointList) { 10 $this->hardpointList = clone $this->hardpointList; 11 } 12 } 13 14 final public function getHardpoint($hardpoint) { 15 return $this->getHardpointList()->getHardpoint( 16 $this, 17 $hardpoint); 18 } 19 20 final public function attachHardpoint($hardpoint, $value) { 21 $this->getHardpointList()->attachHardpoint( 22 $this, 23 $hardpoint, 24 $value); 25 26 return $this; 27 } 28 29 final public function mergeHardpoint($hardpoint, $value) { 30 $hardpoint_list = $this->getHardpointList(); 31 $hardpoint_def = $hardpoint_list->getHardpointDefinition( 32 $this, 33 $hardpoint); 34 35 $old_value = $this->getHardpoint($hardpoint); 36 $new_value = $hardpoint_def->mergeHardpointValues( 37 $this, 38 $old_value, 39 $value); 40 41 $hardpoint_list->setHardpointValue( 42 $this, 43 $hardpoint, 44 $new_value); 45 46 return $this; 47 } 48 49 final public function hasHardpoint($hardpoint) { 50 return $this->getHardpointList()->hasHardpoint($this, $hardpoint); 51 } 52 53 final public function hasAttachedHardpoint($hardpoint) { 54 return $this->getHardpointList()->hasAttachedHardpoint( 55 $this, 56 $hardpoint); 57 } 58 59 protected function newHardpoints() { 60 return array(); 61 } 62 63 final protected function newHardpoint($hardpoint_key) { 64 return id(new ArcanistScalarHardpoint()) 65 ->setHardpointKey($hardpoint_key); 66 } 67 68 final protected function newVectorHardpoint($hardpoint_key) { 69 return id(new ArcanistVectorHardpoint()) 70 ->setHardpointKey($hardpoint_key); 71 } 72 73 final protected function newTemplateHardpoint( 74 $hardpoint_key, 75 ArcanistHardpoint $template) { 76 77 return id(clone $template) 78 ->setHardpointKey($hardpoint_key); 79 } 80 81 82 final public function getHardpointList() { 83 if ($this->hardpointList === null) { 84 $list = $this->newHardpointList(); 85 86 // TODO: Cache the hardpoint list with the class name as a key? If so, 87 // it needs to be purged when the request cache is purged. 88 89 $hardpoints = $this->newHardpoints(); 90 91 // TODO: Verify the hardpoints list is structured properly. 92 93 $list->setHardpoints($hardpoints); 94 95 $this->hardpointList = $list; 96 } 97 98 return $this->hardpointList; 99 } 100 101 private function newHardpointList() { 102 return new ArcanistHardpointList(); 103 } 104 105} 106