From 643216d26d56033b84fb46bff8d8335d9db76e52 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 10 Oct 2023 20:13:48 -0700 Subject: [PATCH] phpstorm - Generate hints for Civi::url() and CRM_Utils_System::url() --- .../phpstorm/Civi/PhpStorm/UrlGenerator.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tools/extensions/phpstorm/Civi/PhpStorm/UrlGenerator.php diff --git a/tools/extensions/phpstorm/Civi/PhpStorm/UrlGenerator.php b/tools/extensions/phpstorm/Civi/PhpStorm/UrlGenerator.php new file mode 100644 index 0000000000..45b16b1504 --- /dev/null +++ b/tools/extensions/phpstorm/Civi/PhpStorm/UrlGenerator.php @@ -0,0 +1,59 @@ + 'generate', + ]; + } + + public function generate() { + $routes = Route::get(FALSE) + ->addSelect('path', 'is_public', 'page_callback') + ->addOrderBy('path') + ->execute(); + + $urls = []; + foreach ($routes as $route) { + // $callback = (is_array($route['page_callback'])) ? $route['page_callback'][0] : $route['page_callback']; + // $suffix = (preg_match('/_Form_/', $callback ?? '')) ? '?reset=1' : ''; + $suffix = ''; + + if (preg_match('/(ajax|ipn)/', $route['path'])) { + // We should have real metadata for web-service routes, but we'll use this weak guess for now... + $urls[] = "service://" . $route['path']; + } + $urls[] = (empty($route['is_public']) ? 'backend' : 'frontend') . "://" . $route['path'] . $suffix; + $urls[] = "current://" . $route['path'] . $suffix; + $urls[] = "default://" . $route['path'] . $suffix; + } + foreach (\CRM_Extension_System::singleton()->getFullContainer()->getKeys() as $key) { + $urls[] = "ext://$key/"; + } + foreach (array_keys(Invasive::get([\Civi::paths(), 'variableFactory'])) as $pathVar) { + $urls[] = "asset://[$pathVar]/"; + } + $urls[] = 'assetBuilder://'; /* Currently don't have a feed listing buildable assets... */ + + $builder = new PhpStormMetadata('urls', __CLASS__); + $builder->registerArgumentsSet('routes', ...$routes->column('path')); + $builder->registerArgumentsSet('urls', ...$urls); + $builder->addExpectedArguments('\CRM_Utils_System::url()', 0, 'routes'); + $builder->addExpectedArguments('\Civi::url()', 0, 'urls'); + + $builder->write(); + } + +} -- 2.25.1