| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace Tools;
- /**
- * Will manager new connections to the server
- * and try to match the requests and the controllers
- **/
- class Router
- {
- /**
- * @var string $rootPath
- * Contains the application's root path (ex: http://myshop.com/) with trailing slash
- * Can be accessed read-only via $instance->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;
- }
- }
- }
|