|
|
@@ -2,11 +2,34 @@
|
|
|
|
|
|
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"], "/");
|
|
|
@@ -15,6 +38,11 @@ class Router
|
|
|
$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");
|
|
|
@@ -25,18 +53,38 @@ class Router
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function getModulesPath()
|
|
|
- { return $this->rootPath . "content/modules/"; }
|
|
|
-
|
|
|
+ /**
|
|
|
+ * @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
|
|
|
+ //TODO@2
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Append local routes to router
|
|
|
+ * Will load CMS pages, categories page, products page, cart pages, etc.
|
|
|
+ **/
|
|
|
private function prepareUrl()
|
|
|
{
|
|
|
- //TODO add internal route config
|
|
|
+ //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;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|