rootPath **/ private $rootPath; /** * @var string $rootPath * Contains the application's root path (ex: /srv/http/myshop/) with trailing slash * Can be accessed read-only via $instance->rootUrl **/ private $rootUrl; /** * @var string $modulePath * Contains the module directory **/ /** * Create the router, initialize url and path **/ public function __construct() { $pos = strrpos($_SERVER["SCRIPT_NAME"], "/"); $relativePath = (($pos === FALSE) ? "" : substr($_SERVER["SCRIPT_NAME"], 0, $pos)); $this->rootPath = $_SERVER["DOCUMENT_ROOT"] . $relativePath . "/"; $this->rootUrl = $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["HTTP_HOST"] . $relativePath ."/"; } /** * TODO@1 This function SHOULD be disabled by configuration * Called after database initialization * Check the site url and redirect user if the HOST does not match **/ public function init() { $siteUrl = \Entity\Config::getConfig(null, "siteUrl"); if ($siteUrl != $_SERVER["HTTP_HOST"]) { header("location: http://{$siteUrl}{$_SERVER['REQUEST_URI']}"); die; } } /** * @return \Controller\AController controller * /core/controller/AController.php * Match request to a controller * return FALSE on failure (eg. 404) **/ public function serveUrl() { $this->prepareUrl(); //TODO@2 } /** * Append local routes to router * Will load CMS pages, categories page, products page, cart pages, etc. **/ private function prepareUrl() { //TODO@2 add internal route config } /** * TODO@1 check end of tag to format url and paths **/ public function __get($key) { switch ($key) { case "rootPath": return $this->rootPath; break; case "rootUrl": return $this->rootUrl; break; case "modulesPath": return $this->rootPath."content/modules/"; break; } } }