Router.php 992 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Tools;
  3. class Router
  4. {
  5. private $rootPath;
  6. private $rootUrl;
  7. public function __construct()
  8. {
  9. $pos = strrpos($_SERVER["SCRIPT_NAME"], "/");
  10. $relativePath = (($pos === FALSE) ? "" : substr($_SERVER["SCRIPT_NAME"], 0, $pos));
  11. $this->rootPath = $_SERVER["DOCUMENT_ROOT"] . $relativePath . "/";
  12. $this->rootUrl = $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["HTTP_HOST"] . $relativePath ."/";
  13. }
  14. public function init()
  15. {
  16. $siteUrl = \Entity\Config::getConfig(null, "siteUrl");
  17. if ($siteUrl != $_SERVER["HTTP_HOST"])
  18. {
  19. header("location: http://{$siteUrl}{$_SERVER['REQUEST_URI']}");
  20. die;
  21. }
  22. }
  23. public function getModulesPath()
  24. { return $this->rootPath . "content/modules/"; }
  25. public function serveUrl()
  26. {
  27. $this->prepareUrl();
  28. //TODO
  29. }
  30. private function prepareUrl()
  31. {
  32. //TODO add internal route config
  33. }
  34. }