Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Core;
- if (!defined('URL')) {
- header("Location: /");
- exit();
- }
- class ConfigController
- {
- private $url;
- private $urlSet;
- private $urlController;
- private $urlParameters;
- public function __construct()
- {
- if (!empty($this->url = filter_input(INPUT_GET, "url", FILTER_DEFAULT))) {
- $this->url = filter_input(INPUT_GET, "url", FILTER_DEFAULT);
- $this->cleanUrl();
- $this->urlSet = explode("/", $this->url);
- if (isset($this->urlSet[0])) {
- $this->urlController = $this->slugController($this->urlSet[0]);
- }else{
- $this->urlController = 'Home';
- }
- if (isset($this->urlSet[1])) {
- $this->urlParameters = $this->urlSet[1];
- }else{
- $this->urlParameters = null;
- }
- }else{
- $this->urlController = 'Home';
- $this->urlParameters = 'Index';
- }
- }
- private function cleanUrl(){
- $this->url = strip_tags($this->url);
- $this->url = trim($this->url);
- $this->url = rtrim($this->url, "/");
- $this->url = strtolower($this->url);
- $this->url = str_replace(" ", "-", $this->url);
- $this->url = preg_replace('/[áàãâä]/ui', 'a', $this->url);
- $this->url = preg_replace('/[éèêë]/ui', 'e', $this->url);
- $this->url = preg_replace('/[íìîï]/ui', 'i', $this->url);
- $this->url = preg_replace('/[óòõôö]/ui', 'o', $this->url);
- $this->url = preg_replace('/[úùûü]/ui', 'u', $this->url);
- $this->url = preg_replace('/[ç]/ui', 'c', $this->url);
- $this->url = preg_replace('/_+/', '', $this->url);
- }
- private function slugController($slugController){
- $UrlController = str_replace(" ", "", ucwords(implode(" ", explode("-", strtolower($slugController)))));
- return $UrlController;
- }
- public function load(){
- $class = "\\App\\Source\\".$this->urlController;
- $loadClass = new $class;
- $loadClass->index();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement