Changeset View
Standalone View
src/applications/diffusion/symbol/PhpExternalSymbolsSource.php
- This file was added.
<?php | |||||
final class PhpExternalSymbolsSource extends ExternalSymbolsSource { | |||||
epriestley: For consistency, prefer `Diffusion...` at the beginning of the classname. | |||||
public function lookupSymbol(array $params) { | |||||
if (idx($params, 'lang', 'php') != 'php') { | |||||
joshuaspenceUnsubmitted Done Inline ActionsMaybe this class should provide a getSupportedLanguages() method joshuaspence: Maybe this class should provide a `getSupportedLanguages()` method | |||||
return null; | |||||
} | |||||
$name = idx($params, 'name'); | |||||
if (!$name) { | |||||
Done Inline ActionsMaybe simpler with a convenience method on the Query, something like: $query->includesAnyOfTheseLanguages($list_of_languages)? Presumably all or almost all external sources will do this as their first check. epriestley: Maybe simpler with a convenience method on the Query, something like: `$query… | |||||
return null; | |||||
} | |||||
if (idx($params, 'type', 'function') == 'function') { | |||||
$functions = get_defined_functions(); | |||||
joshuaspenceUnsubmitted Done Inline ActionsThis won't work if the symbol is from a later version of PHP than the Phabricator installation is using. It would be better if we could read this from a file like php_compat_info.json. joshuaspence: This won't work if the symbol is from a later version of PHP than the Phabricator installation… | |||||
aviveyAuthorUnsubmitted Not Done Inline ActionsI might punt on this for a day or two while we finalize the framework first. avivey: I might punt on this for a day or two while we finalize the framework first. | |||||
if (in_array($name, $functions['internal'])) { | |||||
return 'http://www.php.net/function.'.$name; | |||||
Not Done Inline ActionsI've filed this as T8349 avivey: I've filed this as T8349 | |||||
} | |||||
} | |||||
if (idx($params, 'type', 'class') == 'class') { | |||||
if (class_exists($name, false) || interface_exists($name, false)) { | |||||
if (id(new ReflectionClass($name))->isInternal()) { | |||||
joshuaspenceUnsubmitted Not Done Inline ActionsAs above. joshuaspence: As above. | |||||
return 'http://www.php.net/class.'.$name; | |||||
} | |||||
} | |||||
} | |||||
Done Inline ActionsI guess arguably the source should be pht()'d too since it's human-readable text, even though the translation is presumably always "PHP". epriestley: I guess arguably the source should be pht()'d too since it's human-readable text, even though… | |||||
} | |||||
Done Inline Actionspht() epriestley: pht() | |||||
} | |||||
Done Inline Actionspht() epriestley: pht() | |||||
Not Done Inline ActionsThese should possibly be "php" and "py" or "python" (approximately, file extensions)? I guess it doesn't really matter now, but in theory whatever we set here should be some machine-readable constant representing the language, and we'd like to be able to go from "X.java" -> language constant -> look up symbols matching that language constant. The mapping from "X.java" to language constants is currently very crude, I think: we just take the file extension. But maybe we do slightly better than that today? Some day we should have a formal way to do this -- it's just complicated because a lot of the mapping rules we use in practice are implicit rules inside of Pygments (see T3626 for some discussion). We could put a "language constant" -> "human language name" mapping at the display level so things could read "PHP" and "Python" instead of "php" and "python" to clean the UI up. We also might need to eventually encode language variants, to deal with the python2 vs python3 case and the Zend/HHVM/Hack case and whatever else. epriestley: These should possibly be "php" and "py" or "python" (approximately, file extensions)?
I guess… | |||||
Not Done Inline ActionsI agree we could do better with language detection, but for now just using the common file extension would probably be good. avivey: I agree we could do better with language detection, but for now just using the common file… |
For consistency, prefer Diffusion... at the beginning of the classname.