Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Core;
  4.  
  5. if (!defined('URL')) {
  6. header("Location: /");
  7. exit();
  8. }
  9.  
  10. class ConfigController
  11. {
  12. private $url;
  13. private $urlSet;
  14. private $urlController;
  15. private $urlParameters;
  16.  
  17. public function __construct()
  18. {
  19. if (!empty($this->url = filter_input(INPUT_GET, "url", FILTER_DEFAULT))) {
  20. $this->url = filter_input(INPUT_GET, "url", FILTER_DEFAULT);
  21. $this->cleanUrl();
  22. $this->urlSet = explode("/", $this->url);
  23.  
  24. if (isset($this->urlSet[0])) {
  25. $this->urlController = $this->slugController($this->urlSet[0]);
  26. }else{
  27. $this->urlController = 'Home';
  28. }
  29.  
  30. if (isset($this->urlSet[1])) {
  31. $this->urlParameters = $this->urlSet[1];
  32. }else{
  33. $this->urlParameters = null;
  34. }
  35. }else{
  36. $this->urlController = 'Home';
  37. $this->urlParameters = 'Index';
  38. }
  39. }
  40.  
  41. private function cleanUrl(){
  42. $this->url = strip_tags($this->url);
  43. $this->url = trim($this->url);
  44. $this->url = rtrim($this->url, "/");
  45. $this->url = strtolower($this->url);
  46. $this->url = str_replace(" ", "-", $this->url);
  47. $this->url = preg_replace('/[áàãâä]/ui', 'a', $this->url);
  48. $this->url = preg_replace('/[éèêë]/ui', 'e', $this->url);
  49. $this->url = preg_replace('/[íìîï]/ui', 'i', $this->url);
  50. $this->url = preg_replace('/[óòõôö]/ui', 'o', $this->url);
  51. $this->url = preg_replace('/[úùûü]/ui', 'u', $this->url);
  52. $this->url = preg_replace('/[ç]/ui', 'c', $this->url);
  53. $this->url = preg_replace('/_+/', '', $this->url);
  54. }
  55.  
  56. private function slugController($slugController){
  57. $UrlController = str_replace(" ", "", ucwords(implode(" ", explode("-", strtolower($slugController)))));
  58. return $UrlController;
  59. }
  60.  
  61. public function load(){
  62. $class = "\\App\\Source\\".$this->urlController;
  63. $loadClass = new $class;
  64. $loadClass->index();
  65. }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement