From 9b56c7e8a1253ad0ad500da051c7dcf12a6a8701 Mon Sep 17 00:00:00 2001 From: vrana Date: Thu, 1 Mar 2012 12:12:56 -0800 Subject: [PATCH] Create script printing controller name based on URL Summary: With this script, I am able to add bookmarklet to my browser which edits the controller responsible for displaying current page by a single click. Plus it can be useful also for other uses. Test Plan: ./aphrontpath.php / ./aphrontpath.php D123 ./aphrontpath.php /D123 ./aphrontpath.php /D123/ # doesn't exist ./aphrontpath.php https://secure.phabricator.com/D123 ./aphrontpath.php https://secure.phabricator.com/D123?x=2 ./aphrontpath.php https://secure.phabricator.com/D123#comment-1 ./aphrontpath.php differential ./aphrontpath.php /differential/ ./aphrontpath.php /w/ # rewritten by custom config Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley Maniphest Tasks: T349 Differential Revision: https://secure.phabricator.com/D1746 --- scripts/aphront/aphrontpath.php | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 scripts/aphront/aphrontpath.php diff --git a/scripts/aphront/aphrontpath.php b/scripts/aphront/aphrontpath.php new file mode 100755 index 0000000000..07b9d86730 --- /dev/null +++ b/scripts/aphront/aphrontpath.php @@ -0,0 +1,43 @@ +#!/usr/bin/env php +\n"; + echo "Purpose: Print controller which will process passed .\n"; + exit(1); +} + +$url = parse_url($argv[1]); +$path = '/'.(isset($url['path']) ? ltrim($url['path'], '/') : ''); + +$config_key = 'aphront.default-application-configuration-class'; +$config_class = PhabricatorEnv::getEnvConfig($config_key); +$application = newv($config_class, array()); +$mapper = new AphrontURIMapper($application->getURIMap()); + +list($controller) = $mapper->mapPath($path); +if (!$controller && $path[strlen($path) - 1] !== '/') { + list($controller) = $mapper->mapPath($path.'/'); +} +if ($controller) { + echo "$controller\n"; +}