[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * View which renders down to a single tag, and provides common access for tag 5 * attributes (setting classes, sigils, IDs, etc). 6 */ 7 abstract class AphrontTagView extends AphrontView { 8 9 private $id; 10 private $classes = array(); 11 private $sigils = array(); 12 private $style; 13 private $metadata; 14 private $mustCapture; 15 private $workflow; 16 17 public function setWorkflow($workflow) { 18 $this->workflow = $workflow; 19 return $this; 20 } 21 22 public function getWorkflow() { 23 return $this->workflow; 24 } 25 26 public function setMustCapture($must_capture) { 27 $this->mustCapture = $must_capture; 28 return $this; 29 } 30 31 public function getMustCapture() { 32 return $this->mustCapture; 33 } 34 35 final public function setMetadata(array $metadata) { 36 $this->metadata = $metadata; 37 return $this; 38 } 39 40 final public function getMetadata() { 41 return $this->metadata; 42 } 43 44 final public function setStyle($style) { 45 $this->style = $style; 46 return $this; 47 } 48 49 final public function getStyle() { 50 return $this->style; 51 } 52 53 final public function addSigil($sigil) { 54 $this->sigils[] = $sigil; 55 return $this; 56 } 57 58 final public function getSigils() { 59 return $this->sigils; 60 } 61 62 public function addClass($class) { 63 $this->classes[] = $class; 64 return $this; 65 } 66 67 public function getClasses() { 68 return $this->classes; 69 } 70 71 public function setID($id) { 72 $this->id = $id; 73 return $this; 74 } 75 76 public function getID() { 77 return $this->id; 78 } 79 80 protected function getTagName() { 81 return 'div'; 82 } 83 84 protected function getTagAttributes() { 85 return array(); 86 } 87 88 protected function getTagContent() { 89 return $this->renderChildren(); 90 } 91 92 protected function willRender() { 93 return; 94 } 95 96 final public function render() { 97 $this->willRender(); 98 99 $attributes = $this->getTagAttributes(); 100 101 $implode = array('class', 'sigil'); 102 foreach ($implode as $attr) { 103 if (isset($attributes[$attr])) { 104 if (is_array($attributes[$attr])) { 105 $attributes[$attr] = implode(' ', $attributes[$attr]); 106 } 107 } 108 } 109 110 if (!is_array($attributes)) { 111 $class = get_class($this); 112 throw new Exception( 113 pht("View '%s' did not return an array from getTagAttributes()!", 114 $class)); 115 } 116 117 $sigils = $this->sigils; 118 if ($this->workflow) { 119 $sigils[] = 'workflow'; 120 } 121 122 $tag_view_attributes = array( 123 'id' => $this->id, 124 125 'class' => implode(' ', $this->classes), 126 'style' => $this->style, 127 128 'meta' => $this->metadata, 129 'sigil' => $sigils ? implode(' ', $sigils) : null, 130 'mustcapture' => $this->mustCapture, 131 ); 132 133 foreach ($tag_view_attributes as $key => $value) { 134 if ($value === null) { 135 continue; 136 } 137 if (!isset($attributes[$key])) { 138 $attributes[$key] = $value; 139 continue; 140 } 141 switch ($key) { 142 case 'class': 143 case 'sigil': 144 $attributes[$key] = $attributes[$key].' '.$value; 145 break; 146 default: 147 // Use the explicitly set value rather than the tag default value. 148 $attributes[$key] = $value; 149 break; 150 } 151 } 152 153 return javelin_tag( 154 $this->getTagName(), 155 $attributes, 156 $this->getTagContent()); 157 } 158 }
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 |