/** * Get the base URL, possibly with a controller script * @param bool $with_possible_controller * Defaults to false. If this is true, and if the URL contains * the controller script, then the controller script is included * in the return value. You can also pass a string here, which * will then be simply appended as the controller. */ static function baseUrl($with_possible_controller = false) { if (isset(self::$base_url)) { if (is_string($with_possible_controller)) { if (empty($with_possible_controller)) { return self::$app_root_url; } return self::$app_root_url . "/" . $with_possible_controller; } if ($with_possible_controller) { return self::$base_url; } return self::$app_root_url; } if (isset($_SERVER['SERVER_NAME'])) { // This is a web request, so we can automatically determine // the app root URL. If you want the canonical one which the developer // may have specified in the config field "pie"/"web"/"appRootUrl" // then just query it via Pie_Config::get(). // Infer things if (defined('APP_CONTROLLER_URL')) { self::$controller_url = APP_CONTROLLER_URL; } else { self::$controller_url = self::inferControllerUrl(); } // Get the app root URL self::$app_root_url = self::getAppRootUrl(); // Automatically figure out whether to omit // the controller name from the url self::$controller_present = 0 == strncmp($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'], strlen($_SERVER['SCRIPT_NAME'])); self::$base_url = self::$controller_present ? self::$controller_url : self::$app_root_url; } else { // This is not a web request, and we absolutely need // the canonical app root URL to have been specified. $ar = Pie_Config::get('pie', 'web', 'appRootUrl', false); if (!$ar) { throw new Pie_Exception_MissingConfig(array('fieldpath' => 'pie/web/appRootUrl')); } $cs = Pie_Config::get('pie', 'web', 'controllerSuffix', ''); self::$app_root_url = $ar; self::$controller_url = $ar . $cs; self::$controller_present = false; self::$base_url = self::$app_root_url; } if (is_string($with_possible_controller)) { return self::$app_root_url . "/" . $with_possible_controller; } if ($with_possible_controller) { return self::$base_url; } return self::$app_root_url; }