Advertisement
joserobertocordeiro

Untitled

Sep 26th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <?php
  2. class Core {
  3.  
  4. public function run() {
  5.  
  6. $url = '/';
  7. if(isset($_GET['url'])) {
  8. $url .= $_GET['url'];
  9. }
  10.  
  11. $params = array();
  12.  
  13. if(!empty($url) && $url != '/') {
  14. $url = explode('/', $url);
  15. array_shift($url);
  16.  
  17. $currentController = $url[0].'Controller';
  18. array_shift($url);
  19.  
  20. if(isset($url[0]) && !empty($url[0])) {
  21. $currentAction = $url[0];
  22. array_shift($url);
  23. } else {
  24. $currentAction = 'index';
  25. }
  26.  
  27. if(count($url) > 0) {
  28. $params = $url;
  29. }
  30.  
  31. } else {
  32. $currentController = 'homeController';
  33. $currentAction = 'index';
  34. }
  35.  
  36. if(!file_exists('controllers/'.$currentController.'.php') || !method_exists($currentController, $currentAction)) {
  37. $currentController = 'notfoundController';
  38. $currentAction = 'index';
  39. }
  40.  
  41. $c = new $currentController();
  42.  
  43. call_user_func_array(array($c, $currentAction), $params);
  44.  
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement