Changeset View
Changeset View
Standalone View
Standalone View
src/applications/celerity/CelerityResourceMapGenerator.php
Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | EOFILE; | ||||
*/ | */ | ||||
private function rebuildBinaryResources( | private function rebuildBinaryResources( | ||||
CelerityPhysicalResources $resources) { | CelerityPhysicalResources $resources) { | ||||
$binary_map = $resources->findBinaryResources(); | $binary_map = $resources->findBinaryResources(); | ||||
$result_map = array(); | $result_map = array(); | ||||
foreach ($binary_map as $name => $data_hash) { | foreach ($binary_map as $name => $data_hash) { | ||||
$hash = $resources->getCelerityHash($data_hash.$name); | $hash = $this->newResourceHash($data_hash.$name); | ||||
$result_map[$name] = array( | $result_map[$name] = array( | ||||
'hash' => $hash, | 'hash' => $hash, | ||||
'uri' => $resources->getResourceURI($hash, $name), | 'uri' => $resources->getResourceURI($hash, $name), | ||||
); | ); | ||||
} | } | ||||
return $result_map; | return $result_map; | ||||
Show All 12 Lines | private function rebuildTextResources( | ||||
$text_map = $resources->findTextResources(); | $text_map = $resources->findTextResources(); | ||||
$result_map = array(); | $result_map = array(); | ||||
foreach ($text_map as $name => $data_hash) { | foreach ($text_map as $name => $data_hash) { | ||||
$raw_data = $resources->getResourceData($name); | $raw_data = $resources->getResourceData($name); | ||||
$xformed_data = $xformer->transformResource($name, $raw_data); | $xformed_data = $xformer->transformResource($name, $raw_data); | ||||
$data_hash = $resources->getCelerityHash($xformed_data); | $data_hash = $this->newResourceHash($xformed_data); | ||||
$hash = $resources->getCelerityHash($data_hash.$name); | $hash = $this->newResourceHash($data_hash.$name); | ||||
list($provides, $requires) = $this->getProvidesAndRequires( | list($provides, $requires) = $this->getProvidesAndRequires( | ||||
$name, | $name, | ||||
$raw_data); | $raw_data); | ||||
$result_map[$name] = array( | $result_map[$name] = array( | ||||
'hash' => $hash, | 'hash' => $hash, | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | foreach ($package_spec as $package_name => $package_symbols) { | ||||
$package_name, | $package_name, | ||||
$type, | $type, | ||||
$resource_type)); | $resource_type)); | ||||
} | } | ||||
$hashes[] = $symbol.':'.$symbol_hash; | $hashes[] = $symbol.':'.$symbol_hash; | ||||
} | } | ||||
$hash = $resources->getCelerityHash(implode("\n", $hashes)); | $hash = $this->newResourceHash(implode("\n", $hashes)); | ||||
$package_map[$package_name] = array( | $package_map[$package_name] = array( | ||||
'hash' => $hash, | 'hash' => $hash, | ||||
'symbols' => $package_symbols, | 'symbols' => $package_symbols, | ||||
); | ); | ||||
} | } | ||||
return $package_map; | return $package_map; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | private function parseResourceSymbolList($list) { | ||||
$list = implode(' ', $list); | $list = implode(' ', $list); | ||||
$list = trim($list); | $list = trim($list); | ||||
$list = preg_split('/\s+/', $list); | $list = preg_split('/\s+/', $list); | ||||
$list = array_filter($list); | $list = array_filter($list); | ||||
return $list; | return $list; | ||||
} | } | ||||
private function newResourceHash($data) { | |||||
// This HMAC key is a static, hard-coded value because we don't want the | |||||
// hashes in the map to depend on database state: when two different | |||||
// developers regenerate the map, they should end up with the same output. | |||||
$hash = PhabricatorHash::digestHMACSHA256($data, 'celerity-resource-data'); | |||||
return substr($hash, 0, 8); | |||||
} | |||||
} | } |