Changeset View
Changeset View
Standalone View
Standalone View
src/applications/celerity/CelerityStaticResourceResponse.php
<?php | <?php | ||||
/** | /** | ||||
* Tracks and resolves dependencies the page declares with | * Tracks and resolves dependencies the page declares with | ||||
* @{function:require_celerity_resource}, and then builds appropriate HTML or | * @{function:require_celerity_resource}, and then builds appropriate HTML or | ||||
* Ajax responses. | * Ajax responses. | ||||
*/ | */ | ||||
final class CelerityStaticResourceResponse extends Phobject { | final class CelerityStaticResourceResponse extends Phobject { | ||||
private $symbols = array(); | private $symbols = array(); | ||||
private $needsResolve = true; | private $needsResolve = true; | ||||
private $resolved; | private $resolved; | ||||
private $packaged; | private $packaged; | ||||
private $metadata = array(); | private $metadata = array(); | ||||
private $metadataBlock = 0; | private $metadataBlock = 0; | ||||
private $metadataLocked; | |||||
private $behaviors = array(); | private $behaviors = array(); | ||||
private $hasRendered = array(); | private $hasRendered = array(); | ||||
private $postprocessorKey; | private $postprocessorKey; | ||||
public function __construct() { | public function __construct() { | ||||
if (isset($_REQUEST['__metablock__'])) { | if (isset($_REQUEST['__metablock__'])) { | ||||
$this->metadataBlock = (int)$_REQUEST['__metablock__']; | $this->metadataBlock = (int)$_REQUEST['__metablock__']; | ||||
} | } | ||||
} | } | ||||
public function addMetadata($metadata) { | public function addMetadata($metadata) { | ||||
if ($this->metadataLocked) { | |||||
throw new Exception( | |||||
pht( | |||||
'Attempting to add more metadata after metadata has been '. | |||||
'locked.')); | |||||
} | |||||
$id = count($this->metadata); | $id = count($this->metadata); | ||||
$this->metadata[$id] = $metadata; | $this->metadata[$id] = $metadata; | ||||
return $this->metadataBlock.'_'.$id; | return $this->metadataBlock.'_'.$id; | ||||
} | } | ||||
public function getMetadataBlock() { | public function getMetadataBlock() { | ||||
return $this->metadataBlock; | return $this->metadataBlock; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | private function renderResource( | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Unable to render resource "%s", which has unknown type "%s".', | 'Unable to render resource "%s", which has unknown type "%s".', | ||||
$name, | $name, | ||||
$type)); | $type)); | ||||
} | } | ||||
public function renderHTMLFooter() { | public function renderHTMLFooter() { | ||||
$this->metadataLocked = true; | |||||
$data = array(); | $data = array(); | ||||
if ($this->metadata) { | if ($this->metadata) { | ||||
$json_metadata = AphrontResponse::encodeJSONForHTTPResponse( | $json_metadata = AphrontResponse::encodeJSONForHTTPResponse( | ||||
$this->metadata); | $this->metadata); | ||||
$this->metadata = array(); | $this->metadata = array(); | ||||
} else { | } else { | ||||
$json_metadata = '{}'; | $json_metadata = '{}'; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |