Page MenuHomePhabricator

D13036.id31430.diff
No OneTemporary

D13036.id31430.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -753,6 +753,7 @@
'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php',
'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php',
'DrydockWorkingCopyBlueprintImplementation' => 'applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php',
+ 'ExternalSymbolsSource' => 'applications/diffusion/symbol/ExternalSymbolsSource.php',
'FeedConduitAPIMethod' => 'applications/feed/conduit/FeedConduitAPIMethod.php',
'FeedPublishConduitAPIMethod' => 'applications/feed/conduit/FeedPublishConduitAPIMethod.php',
'FeedPublisherHTTPWorker' => 'applications/feed/worker/FeedPublisherHTTPWorker.php',
@@ -2955,6 +2956,7 @@
'PhortuneSubscriptionWorker' => 'applications/phortune/worker/PhortuneSubscriptionWorker.php',
'PhortuneTestPaymentProvider' => 'applications/phortune/provider/PhortuneTestPaymentProvider.php',
'PhortuneWePayPaymentProvider' => 'applications/phortune/provider/PhortuneWePayPaymentProvider.php',
+ 'PhpExternalSymbolsSource' => 'applications/diffusion/symbol/PhpExternalSymbolsSource.php',
'PhragmentBrowseController' => 'applications/phragment/controller/PhragmentBrowseController.php',
'PhragmentCanCreateCapability' => 'applications/phragment/capability/PhragmentCanCreateCapability.php',
'PhragmentConduitAPIMethod' => 'applications/phragment/conduit/PhragmentConduitAPIMethod.php',
@@ -3097,6 +3099,7 @@
'ProjectRemarkupRule' => 'applications/project/remarkup/ProjectRemarkupRule.php',
'ProjectRemarkupRuleTestCase' => 'applications/project/remarkup/__tests__/ProjectRemarkupRuleTestCase.php',
'ProjectReplyHandler' => 'applications/project/mail/ProjectReplyHandler.php',
+ 'PythonExternalSymbolsSource' => 'applications/diffusion/symbol/PythonExternalSymbolsSource.php',
'QueryFormattingTestCase' => 'infrastructure/storage/__tests__/QueryFormattingTestCase.php',
'ReleephAuthorFieldSpecification' => 'applications/releeph/field/specification/ReleephAuthorFieldSpecification.php',
'ReleephBranch' => 'applications/releeph/storage/ReleephBranch.php',
@@ -6479,6 +6482,7 @@
'PhortuneSubscriptionWorker' => 'PhabricatorWorker',
'PhortuneTestPaymentProvider' => 'PhortunePaymentProvider',
'PhortuneWePayPaymentProvider' => 'PhortunePaymentProvider',
+ 'PhpExternalSymbolsSource' => 'ExternalSymbolsSource',
'PhragmentBrowseController' => 'PhragmentController',
'PhragmentCanCreateCapability' => 'PhabricatorPolicyCapability',
'PhragmentConduitAPIMethod' => 'ConduitAPIMethod',
@@ -6663,6 +6667,7 @@
'ProjectRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'ProjectRemarkupRuleTestCase' => 'PhabricatorTestCase',
'ProjectReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
+ 'PythonExternalSymbolsSource' => 'ExternalSymbolsSource',
'QueryFormattingTestCase' => 'PhabricatorTestCase',
'ReleephAuthorFieldSpecification' => 'ReleephFieldSpecification',
'ReleephBranch' => array(
diff --git a/src/applications/diffusion/controller/DiffusionSymbolController.php b/src/applications/diffusion/controller/DiffusionSymbolController.php
--- a/src/applications/diffusion/controller/DiffusionSymbolController.php
+++ b/src/applications/diffusion/controller/DiffusionSymbolController.php
@@ -47,26 +47,23 @@
$symbols = $query->execute();
- // For PHP builtins, jump to php.net documentation.
if ($request->getBool('jump') && count($symbols) == 0) {
- if ($request->getStr('lang', 'php') == 'php') {
- if ($request->getStr('type', 'function') == 'function') {
- $functions = get_defined_functions();
- if (in_array($this->name, $functions['internal'])) {
- return id(new AphrontRedirectResponse())
- ->setIsExternal(true)
- ->setURI('http://www.php.net/function.'.$this->name);
- }
- }
- if ($request->getStr('type', 'class') == 'class') {
- if (class_exists($this->name, false) ||
- interface_exists($this->name, false)) {
- if (id(new ReflectionClass($this->name))->isInternal()) {
- return id(new AphrontRedirectResponse())
- ->setIsExternal(true)
- ->setURI('http://www.php.net/class.'.$this->name);
- }
- }
+ $external_sources = id(new PhutilSymbolLoader())
+ ->setAncestorClass('ExternalSymbolsSource')
+ ->loadObjects();
+ $external_sources = msort($external_sources, 'getPriority');
+ $lookup_params = array(
+ 'name' => $this->name,
+ 'lang' => $request->getStr('lang'),
+ 'type' => $request->getStr('type'),
+ 'context' => $request->getStr('context'),
+ );
+ foreach ($external_sources as $source) {
+ $uri = $source->lookupSymbol($lookup_params);
+ if ($uri) {
+ return id(new AphrontRedirectResponse())
+ ->setIsExternal(true)
+ ->setURI($uri);
}
}
}
diff --git a/src/applications/diffusion/symbol/ExternalSymbolsSource.php b/src/applications/diffusion/symbol/ExternalSymbolsSource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/diffusion/symbol/ExternalSymbolsSource.php
@@ -0,0 +1,20 @@
+<?php
+
+abstract class ExternalSymbolsSource {
+
+ /**
+ * $params may contain:
+ * - name
+ * - lang
+ * - type
+ * - context
+ * @return string uri to the symbol online docs, or null.
+ */
+ abstract public function lookupSymbol(array $params);
+
+ public function getPriority() {
+ return 500;
+ }
+
+
+}
diff --git a/src/applications/diffusion/symbol/PhpExternalSymbolsSource.php b/src/applications/diffusion/symbol/PhpExternalSymbolsSource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/diffusion/symbol/PhpExternalSymbolsSource.php
@@ -0,0 +1,27 @@
+<?php
+
+final class PhpExternalSymbolsSource extends ExternalSymbolsSource {
+
+ public function lookupSymbol(array $params) {
+ if (idx($params, 'lang', 'php') != 'php') {
+ return null;
+ }
+ $name = idx($params, 'name');
+ if (!$name) {
+ return null;
+ }
+ if (idx($params, 'type', 'function') == 'function') {
+ $functions = get_defined_functions();
+ if (in_array($name, $functions['internal'])) {
+ return 'http://www.php.net/function.'.$name;
+ }
+ }
+ if (idx($params, 'type', 'class') == 'class') {
+ if (class_exists($name, false) || interface_exists($name, false)) {
+ if (id(new ReflectionClass($name))->isInternal()) {
+ return 'http://www.php.net/class.'.$name;
+ }
+ }
+ }
+ }
+}
diff --git a/src/applications/diffusion/symbol/PythonExternalSymbolsSource.php b/src/applications/diffusion/symbol/PythonExternalSymbolsSource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/diffusion/symbol/PythonExternalSymbolsSource.php
@@ -0,0 +1,99 @@
+<?php
+
+final class PythonExternalSymbolsSource extends ExternalSymbolsSource {
+
+ public function lookupSymbol(array $params) {
+ if (idx($params, 'lang') != 'py') {
+ return null;
+ }
+ $name = idx($params, 'name');
+ if (!$name) {
+ return null;
+ }
+
+ if (idx($params, 'type') == 'builtin') {
+ if (idx(self::$pyhonBuiltins, $name)) {
+ return 'https://docs.python.org/2/library/functions.html#'.$name;
+ }
+ }
+ }
+
+ private static $pyhonBuiltins = array(
+ '__import__' => true,
+ 'abs' => true,
+ 'all' => true,
+ 'any' => true,
+ 'basestring' => true,
+ 'bin' => true,
+ 'bool' => true,
+ 'bytearray' => true,
+ 'callable' => true,
+ 'chr' => true,
+ 'classmethod' => true,
+ 'cmp' => true,
+ 'compile' => true,
+ 'complex' => true,
+ 'delattr' => true,
+ 'dict' => true,
+ 'dir' => true,
+ 'divmod' => true,
+ 'enumerate' => true,
+ 'eval' => true,
+ 'execfile' => true,
+ 'file' => true,
+ 'filter' => true,
+ 'float' => true,
+ 'format' => true,
+ 'frozenset' => true,
+ 'getattr' => true,
+ 'globals' => true,
+ 'hasattr' => true,
+ 'hash' => true,
+ 'help' => true,
+ 'hex' => true,
+ 'id' => true,
+ 'input' => true,
+ 'int' => true,
+ 'isinstance' => true,
+ 'issubclass' => true,
+ 'iter' => true,
+ 'len' => true,
+ 'list' => true,
+ 'locals' => true,
+ 'long' => true,
+ 'map' => true,
+ 'max' => true,
+ 'memoryview' => true,
+ 'min' => true,
+ 'next' => true,
+ 'object' => true,
+ 'oct' => true,
+ 'open' => true,
+ 'ord' => true,
+ 'pow' => true,
+ 'print' => true,
+ 'property' => true,
+ 'range' => true,
+ 'raw_input' => true,
+ 'reduce' => true,
+ 'reload' => true,
+ 'repr' => true,
+ 'reversed' => true,
+ 'round' => true,
+ 'set' => true,
+ 'setattr' => true,
+ 'slice' => true,
+ 'sorted' => true,
+ 'staticmethod' => true,
+ 'str' => true,
+ 'sum' => true,
+ 'super' => true,
+ 'tuple' => true,
+ 'type' => true,
+ 'unichr' => true,
+ 'unicode' => true,
+ 'vars' => true,
+ 'xrange' => true,
+ 'zip' => true,
+ );
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Mar 13, 9:48 PM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7633983
Default Alt Text
D13036.id31430.diff (9 KB)

Event Timeline