Changeset View
Changeset View
Standalone View
Standalone View
src/moduleutils/PhutilLibraryMapBuilder.php
Show First 20 Lines • Show All 337 Lines • ▼ Show 20 Lines | $library_map = 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; | // Treat interfaces and traits provided as classes | ||||
switch ($type) { | |||||
case 'interface': | |||||
case 'trait': | |||||
$lib_type = 'class'; | |||||
break; | |||||
default: | |||||
$lib_type = $type; | |||||
break; | |||||
} | |||||
if (!empty($library_map[$lib_type][$symbol])) { | if (!empty($library_map[$lib_type][$symbol])) { | ||||
$prior = $library_map[$lib_type][$symbol]; | $prior = $library_map[$lib_type][$symbol]; | ||||
throw new Exception( | throw new Exception( | ||||
"Definition of {$type} '{$symbol}' in file '{$file}' duplicates ". | "Definition of {$type} '{$symbol}' in file '{$file}' duplicates ". | ||||
"prior definition in file '{$prior}'. You can not declare the ". | "prior definition in file '{$prior}'. You can not declare the ". | ||||
"same symbol twice."); | "same symbol twice."); | ||||
} | } | ||||
$library_map[$lib_type][$symbol] = $file; | $library_map[$lib_type][$symbol] = $file; | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |