Changeset View
Changeset View
Standalone View
Standalone View
src/moduleutils/PhutilLibraryMapBuilder.php
Show First 20 Lines • Show All 272 Lines • ▼ Show 20 Lines | |||||
/* -( Source Management )-------------------------------------------------- */ | /* -( Source Management )-------------------------------------------------- */ | ||||
/** | /** | ||||
* Build a map of all source files in a library to hashes of their content. | * Build a map of all source files in a library to hashes of their content. | ||||
* Returns an array like this: | * Returns an array like this: | ||||
* | * | ||||
* ```lang=php | |||||
* array( | * array( | ||||
* 'src/parser/ExampleParser.php' => '60b725f10c9c85c70d97880dfe8191b3', | * 'src/parser/ExampleParser.php' => '60b725f10c9c85c70d97880dfe8191b3', | ||||
* // ... | * // ... | ||||
* ); | * ); | ||||
* ``` | |||||
* | * | ||||
* @return dict Map of library-relative paths to content hashes. | * @return dict Map of library-relative paths to content hashes. | ||||
* | |||||
* @task source | * @task source | ||||
*/ | */ | ||||
private function loadSourceFileMap() { | private function loadSourceFileMap() { | ||||
$root = $this->getPath(); | $root = $this->getPath(); | ||||
$init = $this->getPathForLibraryInit(); | $init = $this->getPathForLibraryInit(); | ||||
if (!Filesystem::pathExists($init)) { | if (!Filesystem::pathExists($init)) { | ||||
throw new Exception( | throw new Exception( | ||||
Show All 35 Lines | /* -( Source Management )-------------------------------------------------- */ | ||||
} | } | ||||
/** | /** | ||||
* Convert the symbol analysis of all the source files in the library into | * Convert the symbol analysis of all the source files in the library into | ||||
* a library map. | * a library map. | ||||
* | * | ||||
* @param dict Symbol analysis of all source files. | * @param dict Symbol analysis of all source files. | ||||
* @return dict Library map. | * @return dict Library map. | ||||
* | |||||
* @task source | * @task source | ||||
*/ | */ | ||||
private function buildLibraryMap(array $symbol_map) { | private function buildLibraryMap(array $symbol_map) { | ||||
$library_map = array( | $library_map = array( | ||||
'class' => array(), | 'class' => array(), | ||||
'interface' => array(), | |||||
'function' => array(), | 'function' => array(), | ||||
'xmap' => array(), | 'xmap' => array(), | ||||
); | ); | ||||
// Detect duplicate symbols within the library. | // Detect duplicate symbols within the library. | ||||
foreach ($symbol_map as $file => $info) { | foreach ($symbol_map as $file => $info) { | ||||
foreach ($info['have'] as $type => $symbols) { | foreach ($info['have'] as $type => $symbols) { | ||||
foreach ($symbols as $symbol => $declaration) { | foreach ($symbols as $symbol => $declaration) { | ||||
$lib_type = ($type == 'interface') ? 'class' : $type; | if (!empty($library_map[$type][$symbol])) { | ||||
if (!empty($library_map[$lib_type][$symbol])) { | $prior = $library_map[$type][$symbol]; | ||||
$prior = $library_map[$lib_type][$symbol]; | |||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
"Definition of %s '%s' in file '%s' duplicates prior ". | "Definition of %s '%s' in file '%s' duplicates prior ". | ||||
"definition in file '%s'. You can not declare the ". | "definition in file '%s'. You can not declare the ". | ||||
"same symbol twice.", | "same symbol twice.", | ||||
$type, | $type, | ||||
$symbol, | $symbol, | ||||
$file, | $file, | ||||
$prior)); | $prior)); | ||||
} | } | ||||
$library_map[$lib_type][$symbol] = $file; | $library_map[$type][$symbol] = $file; | ||||
} | } | ||||
} | } | ||||
$library_map['xmap'] += $info['xmap']; | $library_map['xmap'] += $info['xmap']; | ||||
} | } | ||||
// Simplify the common case (one parent) to make the file a little easier | // Simplify the common case (one parent) to make the file a little easier | ||||
// to deal with. | // to deal with. | ||||
foreach ($library_map['xmap'] as $class => $extends) { | foreach ($library_map['xmap'] as $class => $extends) { | ||||
Show All 10 Lines | private function buildLibraryMap(array $symbol_map) { | ||||
ksort($library_map); | ksort($library_map); | ||||
return $library_map; | return $library_map; | ||||
} | } | ||||
/** | /** | ||||
* Write a finalized library map. | * Write a finalized library map. | ||||
* | * | ||||
* @param dict Library map structure to write. | * @param dict Library map structure to write. | ||||
* @return void | * @return void | ||||
* | * | ||||
* @task source | * @task source | ||||
*/ | */ | ||||
private function writeLibraryMap(array $library_map) { | private function writeLibraryMap(array $library_map) { | ||||
$map_file = $this->getPathForLibraryMap(); | $map_file = $this->getPathForLibraryMap(); | ||||
$version = self::LIBRARY_MAP_VERSION; | $version = self::LIBRARY_MAP_VERSION; | ||||
▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines |