|
| 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