Skip to content

Commit 9b56c7e

Browse files
author
vrana
committed
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
1 parent 0327a5f commit 9b56c7e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

scripts/aphront/aphrontpath.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*
5+
* Copyright 2012 Facebook, Inc.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
$root = dirname(dirname(dirname(__FILE__)));
21+
require_once $root.'/scripts/__init_script__.php';
22+
23+
if ($argc !== 2 || $argv[1] === '--help') {
24+
echo "Usage: aphrontpath.php <url>\n";
25+
echo "Purpose: Print controller which will process passed <url>.\n";
26+
exit(1);
27+
}
28+
29+
$url = parse_url($argv[1]);
30+
$path = '/'.(isset($url['path']) ? ltrim($url['path'], '/') : '');
31+
32+
$config_key = 'aphront.default-application-configuration-class';
33+
$config_class = PhabricatorEnv::getEnvConfig($config_key);
34+
$application = newv($config_class, array());
35+
$mapper = new AphrontURIMapper($application->getURIMap());
36+
37+
list($controller) = $mapper->mapPath($path);
38+
if (!$controller && $path[strlen($path) - 1] !== '/') {
39+
list($controller) = $mapper->mapPath($path.'/');
40+
}
41+
if ($controller) {
42+
echo "$controller\n";
43+
}

0 commit comments

Comments
 (0)