@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow CelerityResourceResponse to hold resources from multiple maps

Summary:
Ref T4222. Currently, CelerityResourceResponse holds response resources in flat maps. Instead, specify which map resources appear in.

Also, provide `requireResource()` and `initBehavior()` APIs on the Controller and View base classes. These provide a cleaner abstraction over `require_celerity_resource()` and `Javelin::initBehavior()`, but are otherwise the same. Move a few callsites over.

Test Plan:
- Reloaded pages.
- Browsed around Differential.

Reviewers: btrahan, hach-que

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4222

Differential Revision: https://secure.phabricator.com/D7876

+146 -53
+20 -1
src/aphront/AphrontController.php
··· 9 9 private $currentApplication; 10 10 private $delegatingController; 11 11 12 - 13 12 public function setDelegatingController( 14 13 AphrontController $delegating_controller) { 15 14 $this->delegatingController = $delegating_controller; ··· 62 61 63 62 final public function getCurrentApplication() { 64 63 return $this->currentApplication; 64 + } 65 + 66 + public function getDefaultResourceSource() { 67 + throw new Exception( 68 + pht( 69 + 'A Controller must implement getDefaultResourceSource() before you '. 70 + 'can invoke requireResource() or initBehavior().')); 71 + } 72 + 73 + public function requireResource($symbol) { 74 + $response = CelerityAPI::getStaticResourceResponse(); 75 + $response->requireResource($symbol, $this->getDefaultResourceSource()); 76 + return $this; 77 + } 78 + 79 + public function initBehavior($name, $config = array()) { 80 + Javelin::initBehavior( 81 + $name, 82 + $config, 83 + $this->getDefaultResourceSource()); 65 84 } 66 85 67 86 }
+5
src/applications/base/controller/PhabricatorController.php
··· 408 408 return array($can_act, $message); 409 409 } 410 410 411 + public function getDefaultResourceSource() { 412 + return 'phabricator'; 413 + } 414 + 415 + 411 416 }
+2 -2
src/applications/differential/controller/DifferentialRevisionViewController.php
··· 497 497 ); 498 498 } 499 499 500 - require_celerity_resource('phabricator-object-selector-css'); 501 - require_celerity_resource('javelin-behavior-phabricator-object-selector'); 500 + $this->requireResource('phabricator-object-selector-css'); 501 + $this->requireResource('javelin-behavior-phabricator-object-selector'); 502 502 503 503 $links[] = array( 504 504 'icon' => 'link',
+1 -1
src/applications/differential/view/DifferentialAddCommentView.php
··· 48 48 49 49 public function render() { 50 50 51 - require_celerity_resource('differential-revision-add-comment-css'); 51 + $this->requireResource('differential-revision-add-comment-css'); 52 52 53 53 $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); 54 54
+2 -2
src/applications/differential/view/DifferentialChangesetDetailView.php
··· 94 94 } 95 95 96 96 public function render() { 97 - require_celerity_resource('differential-changeset-view-css'); 98 - require_celerity_resource('syntax-highlighting-css'); 97 + $this->requireResource('differential-changeset-view-css'); 98 + $this->requireResource('syntax-highlighting-css'); 99 99 100 100 Javelin::initBehavior('phabricator-oncopy', array()); 101 101
+5 -5
src/applications/differential/view/DifferentialChangesetListView.php
··· 103 103 } 104 104 105 105 public function render() { 106 - require_celerity_resource('differential-changeset-view-css'); 106 + $this->requireResource('differential-changeset-view-css'); 107 107 108 108 $changesets = $this->changesets; 109 109 ··· 183 183 $output[] = $detail->render(); 184 184 } 185 185 186 - require_celerity_resource('aphront-tooltip-css'); 186 + $this->requireResource('aphront-tooltip-css'); 187 187 188 - Javelin::initBehavior('differential-populate', array( 188 + $this->initBehavior('differential-populate', array( 189 189 'registry' => $mapping, 190 190 'whitespace' => $this->whitespace, 191 191 'uri' => $this->renderURI, 192 192 )); 193 193 194 - Javelin::initBehavior('differential-show-more', array( 194 + $this->initBehavior('differential-show-more', array( 195 195 'uri' => $this->renderURI, 196 196 'whitespace' => $this->whitespace, 197 197 )); 198 198 199 - Javelin::initBehavior('differential-comment-jump', array()); 199 + $this->initBehavior('differential-comment-jump', array()); 200 200 201 201 if ($this->inlineURI) { 202 202 $undo_templates = $this->renderUndoTemplates();
+2 -2
src/applications/differential/view/DifferentialDiffTableOfContentsView.php
··· 54 54 55 55 public function render() { 56 56 57 - require_celerity_resource('differential-core-view-css'); 58 - require_celerity_resource('differential-table-of-contents-css'); 57 + $this->requireResource('differential-core-view-css'); 58 + $this->requireResource('differential-table-of-contents-css'); 59 59 60 60 $rows = array(); 61 61
+1 -1
src/applications/differential/view/DifferentialLocalCommitsView.php
··· 20 20 return null; 21 21 } 22 22 23 - require_celerity_resource('differential-local-commits-view-css'); 23 + $this->requireResource('differential-local-commits-view-css'); 24 24 25 25 $has_tree = false; 26 26 $has_local = false;
+2 -2
src/applications/differential/view/DifferentialResultsTableView.php
··· 97 97 ), 98 98 phutil_tag('th', array('colspan' => 2), $hide_more)); 99 99 100 - Javelin::initBehavior('differential-show-field-details'); 100 + $this->initBehavior('differential-show-field-details'); 101 101 } 102 102 103 - require_celerity_resource('differential-results-table-css'); 103 + $this->requireResource('differential-results-table-css'); 104 104 105 105 return javelin_tag( 106 106 'table',
+2 -2
src/applications/differential/view/DifferentialRevisionCommentListView.php
··· 53 53 54 54 public function render() { 55 55 56 - require_celerity_resource('differential-revision-comment-list-css'); 56 + $this->requireResource('differential-revision-comment-list-css'); 57 57 58 58 $engine = new PhabricatorMarkupEngine(); 59 59 $engine->setViewer($this->user); ··· 154 154 $visible = array_reverse($visible); 155 155 156 156 if ($hidden) { 157 - Javelin::initBehavior( 157 + $this->initBehavior( 158 158 'differential-show-all-comments', 159 159 array( 160 160 'markup' => implode("\n", $hidden),
+2 -2
src/applications/differential/view/DifferentialRevisionCommentView.php
··· 67 67 throw new Exception("Call setUser() before rendering!"); 68 68 } 69 69 70 - require_celerity_resource('phabricator-remarkup-css'); 71 - require_celerity_resource('differential-revision-comment-css'); 70 + $this->requireResource('phabricator-remarkup-css'); 71 + $this->requireResource('differential-revision-comment-css'); 72 72 73 73 $comment = $this->comment; 74 74
+1 -1
src/applications/differential/view/DifferentialRevisionDetailView.php
··· 45 45 46 46 public function render() { 47 47 48 - require_celerity_resource('differential-core-view-css'); 48 + $this->requireResource('differential-core-view-css'); 49 49 50 50 $revision = $this->revision; 51 51 $user = $this->getUser();
+2 -2
src/applications/differential/view/DifferentialRevisionListView.php
··· 102 102 -$stale); 103 103 } 104 104 105 - Javelin::initBehavior('phabricator-tooltips', array()); 106 - require_celerity_resource('aphront-tooltip-css'); 105 + $this->initBehavior('phabricator-tooltips', array()); 106 + $this->requireResource('aphront-tooltip-css'); 107 107 108 108 $flagged = mpull($this->flags, null, 'getObjectPHID'); 109 109
+2 -2
src/applications/differential/view/DifferentialRevisionUpdateHistoryView.php
··· 30 30 31 31 public function render() { 32 32 33 - require_celerity_resource('differential-core-view-css'); 34 - require_celerity_resource('differential-revision-history-css'); 33 + $this->requireResource('differential-core-view-css'); 34 + $this->requireResource('differential-revision-history-css'); 35 35 36 36 $data = array( 37 37 array(
+4
src/infrastructure/celerity/CelerityResourceMap.php
··· 236 236 return isset($this->packageMap[$name]); 237 237 } 238 238 239 + public function getResourceTypeForName($name) { 240 + return $this->resources->getResourceType($name); 241 + } 242 + 239 243 }
+74 -26
src/infrastructure/celerity/CelerityStaticResourceResponse.php
··· 39 39 * a behavior will execute only once even if it is initialized multiple times. 40 40 * If $config is nonempty, the behavior will be invoked once for each config. 41 41 */ 42 - public function initBehavior($behavior, array $config = array()) { 43 - $this->requireResource('javelin-behavior-'.$behavior); 42 + public function initBehavior( 43 + $behavior, 44 + array $config = array(), 45 + $source_name = 'phabricator') { 46 + 47 + $this->requireResource('javelin-behavior-'.$behavior, $source_name); 44 48 45 49 if (empty($this->behaviors[$behavior])) { 46 50 $this->behaviors[$behavior] = array(); ··· 53 57 return $this; 54 58 } 55 59 56 - public function requireResource($symbol) { 57 - $this->symbols[$symbol] = true; 60 + public function requireResource($symbol, $source_name) { 61 + if (isset($this->symbols[$source_name][$symbol])) { 62 + return $this; 63 + } 64 + 65 + // Verify that the resource exists. 66 + $map = CelerityResourceMap::getNamedInstance($source_name); 67 + $name = $map->getResourceNameForSymbol($symbol); 68 + if ($name === null) { 69 + throw new Exception( 70 + pht( 71 + 'No resource with symbol "%s" exists in source "%s"!', 72 + $symbol, 73 + $source_name)); 74 + } 75 + 76 + $this->symbols[$source_name][$symbol] = true; 58 77 $this->needsResolve = true; 78 + 59 79 return $this; 60 80 } 61 81 62 82 private function resolveResources() { 63 83 if ($this->needsResolve) { 64 - $map = CelerityResourceMap::getNamedInstance('phabricator'); 84 + $this->packaged = array(); 85 + foreach ($this->symbols as $source_name => $symbols_map) { 86 + $symbols = array_keys($symbols_map); 65 87 66 - $symbols = array_keys($this->symbols); 67 - $this->packaged = $map->getPackagedNamesForSymbols($symbols); 88 + $map = CelerityResourceMap::getNamedInstance($source_name); 89 + $packaged = $map->getPackagedNamesForSymbols($symbols); 68 90 91 + $this->packaged[$source_name] = $packaged; 92 + } 69 93 $this->needsResolve = false; 70 94 } 71 95 return $this; ··· 74 98 public function renderSingleResource($symbol, $source_name) { 75 99 $map = CelerityResourceMap::getNamedInstance($source_name); 76 100 $packaged = $map->getPackagedNamesForSymbols(array($symbol)); 77 - return $this->renderPackagedResources($packaged); 101 + return $this->renderPackagedResources($map, $packaged); 78 102 } 79 103 80 104 public function renderResourcesOfType($type) { 81 105 $this->resolveResources(); 82 106 83 - $resources = array(); 84 - foreach ($this->packaged as $name) { 85 - $resource_type = CelerityResourceTransformer::getResourceType($name); 86 - if ($resource_type == $type) { 87 - $resources[] = $name; 107 + $result = array(); 108 + foreach ($this->packaged as $source_name => $resource_names) { 109 + $map = CelerityResourceMap::getNamedInstance($source_name); 110 + 111 + $resources_of_type = array(); 112 + foreach ($resource_names as $resource_name) { 113 + $resource_type = $map->getResourceTypeForName($resource_name); 114 + if ($resource_type == $type) { 115 + $resources_of_type[] = $resource_name; 116 + } 88 117 } 118 + 119 + $result[] = $this->renderPackagedResources($map, $resources_of_type); 89 120 } 90 121 91 - return $this->renderPackagedResources($resources); 122 + return phutil_implode_html('', $result); 92 123 } 93 124 94 - private function renderPackagedResources(array $resources) { 125 + private function renderPackagedResources( 126 + CelerityResourceMap $map, 127 + array $resources) { 128 + 95 129 $output = array(); 96 130 foreach ($resources as $name) { 97 131 if (isset($this->hasRendered[$name])) { ··· 99 133 } 100 134 $this->hasRendered[$name] = true; 101 135 102 - $output[] = $this->renderResource($name); 103 - $output[] = "\n"; 136 + $output[] = $this->renderResource($map, $name); 104 137 } 105 - return phutil_implode_html('', $output); 138 + 139 + return $output; 106 140 } 107 141 108 - private function renderResource($name) { 109 - $uri = $this->getURI($name); 110 - $type = CelerityResourceTransformer::getResourceType($name); 142 + private function renderResource( 143 + CelerityResourceMap $map, 144 + $name) { 145 + 146 + $uri = $this->getURI($map, $name); 147 + $type = $map->getResourceTypeForName($name); 148 + 111 149 switch ($type) { 112 150 case 'css': 113 151 return phutil_tag( ··· 126 164 ), 127 165 ''); 128 166 } 129 - throw new Exception("Unable to render resource."); 167 + 168 + throw new Exception( 169 + pht( 170 + 'Unable to render resource "%s", which has unknown type "%s".', 171 + $name, 172 + $type)); 130 173 } 131 174 132 175 public function renderHTMLFooter() { ··· 225 268 226 269 $this->resolveResources(); 227 270 $resources = array(); 228 - foreach ($this->packaged as $resource) { 229 - $resources[] = $this->getURI($resource); 271 + foreach ($this->packaged as $source_name => $resource_names) { 272 + $map = CelerityResourceMap::getNamedInstance($source_name); 273 + foreach ($resource_names as $resource_name) { 274 + $resources[] = $this->getURI($map, $resource_name); 275 + } 230 276 } 231 277 if ($resources) { 232 278 $response['javelin_resources'] = $resources; ··· 235 281 return $response; 236 282 } 237 283 238 - private function getURI($name) { 239 - $map = CelerityResourceMap::getNamedInstance('phabricator'); 284 + private function getURI( 285 + CelerityResourceMap $map, 286 + $name) { 287 + 240 288 $uri = $map->getURIForName($name); 241 289 242 290 // In developer mode, we dump file modification times into the URI. When a
+2 -2
src/infrastructure/celerity/api.php
··· 15 15 * 16 16 * @group celerity 17 17 */ 18 - function require_celerity_resource($symbol) { 18 + function require_celerity_resource($symbol, $source_name = 'phabricator') { 19 19 $response = CelerityAPI::getStaticResourceResponse(); 20 - $response->requireResource($symbol); 20 + $response->requireResource($symbol, $source_name); 21 21 } 22 22 23 23
+17
src/view/AphrontView.php
··· 128 128 return $children; 129 129 } 130 130 131 + public function getDefaultResourceSource() { 132 + return 'phabricator'; 133 + } 134 + 135 + public function requireResource($symbol) { 136 + $response = CelerityAPI::getStaticResourceResponse(); 137 + $response->requireResource($symbol, $this->getDefaultResourceSource()); 138 + return $this; 139 + } 140 + 141 + public function initBehavior($name, $config = array()) { 142 + Javelin::initBehavior( 143 + $name, 144 + $config, 145 + $this->getDefaultResourceSource()); 146 + } 147 + 131 148 132 149 /* -( Rendering )---------------------------------------------------------- */ 133 150