public final function buildController()
 {
     $map = $this->getURIMap();
     $mapper = new AphrontURIMapper($map);
     $request = $this->getRequest();
     $path = $request->getPath();
     list($controller_class, $uri_data) = $mapper->mapPath($path);
     if (!$controller_class) {
         if (!preg_match('@/$@', $path)) {
             // If we failed to match anything but don't have a trailing slash, try
             // to add a trailing slash and issue a redirect if that resolves.
             list($controller_class, $uri_data) = $mapper->mapPath($path . '/');
             // NOTE: For POST, just 404 instead of redirecting, since the redirect
             // will be a GET without parameters.
             if ($controller_class && !$request->isHTTPPost()) {
                 $uri = $request->getRequestURI()->setPath($path . '/');
                 return $this->buildRedirectController($uri);
             }
         }
         return $this->build404Controller();
     }
     PhutilSymbolLoader::loadClass($controller_class);
     $controller = newv($controller_class, array($request));
     return array($controller, $uri_data);
 }
 public final function buildController()
 {
     $map = $this->getURIMap();
     $mapper = new AphrontURIMapper($map);
     $request = $this->getRequest();
     $path = $request->getPath();
     list($controller_class, $uri_data) = $mapper->mapPath($path);
     if (!$controller_class) {
         if (!preg_match('@/$@', $path)) {
             // If we failed to match anything but don't have a trailing slash, try
             // to add a trailing slash and issue a redirect if that resolves.
             list($controller_class, $uri_data) = $mapper->mapPath($path . '/');
             if ($controller_class) {
                 return $this->buildRedirectController($path . '/');
             }
         }
         return $this->build404Controller();
     }
     PhutilSymbolLoader::loadClass($controller_class);
     $controller = newv($controller_class, array($request));
     return array($controller, $uri_data);
 }
 /**
  * Map a specific path to the corresponding controller. For a description
  * of routing, see @{method:buildController}.
  *
  * @return pair<AphrontController,dict> Controller and dictionary of request
  *                                      parameters.
  * @task routing
  */
 public final function buildControllerForPath($path)
 {
     $maps = array();
     $maps[] = array(null, $this->getURIMap());
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $application) {
         $maps[] = array($application, $application->getRoutes());
     }
     $current_application = null;
     $controller_class = null;
     foreach ($maps as $map_info) {
         list($application, $map) = $map_info;
         $mapper = new AphrontURIMapper($map);
         list($controller_class, $uri_data) = $mapper->mapPath($path);
         if ($controller_class) {
             if ($application) {
                 $current_application = $application;
             }
             break;
         }
     }
     if (!$controller_class) {
         return array(null, null);
     }
     $request = $this->getRequest();
     $controller = newv($controller_class, array($request));
     if ($current_application) {
         $controller->setCurrentApplication($current_application);
     }
     return array($controller, $uri_data);
 }
Example #4
0
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
$root = dirname(dirname(dirname(__FILE__)));
require_once $root . '/scripts/__init_script__.php';
if ($argc !== 2 || $argv[1] === '--help') {
    echo "Usage: aphrontpath.php <url>\n";
    echo "Purpose: Print controller which will process passed <url>.\n";
    exit(1);
}
$url = parse_url($argv[1]);
$path = '/' . (isset($url['path']) ? ltrim($url['path'], '/') : '');
$config_key = 'aphront.default-application-configuration-class';
$application = PhabricatorEnv::newObjectFromConfig($config_key);
$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";
}