Advertisement
Guest User

Untitled

a guest
Jul 12th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2.  
  3. define('BASE_PATH', __DIR__);
  4.  
  5. $config = require BASE_PATH . '/config.php';
  6.  
  7. $app = new App($config);
  8.  
  9. class App
  10. {
  11. private $config;
  12.  
  13. public function __construct(array $config)
  14. {
  15. $this->config = $config;
  16. }
  17.  
  18. public function db()
  19. {
  20. if (!isset($this->db)) {
  21. $host = $this->config['db']['host'];
  22. $password = $this->config['db']['password'];
  23. $user = $this->config['db']['user'];
  24. $dbname = $this->config['db']['dbname'];
  25.  
  26. try {
  27. $this->db = new PDO("mysql:host=$host;dbname=$dbname", $user, $password);
  28. } catch (PDOException $e) {
  29. exit('Error: ' . $e->getMessage());
  30. }
  31. }
  32.  
  33. return $this->db;
  34. }
  35.  
  36. /**
  37. * Routes requsts to the correct file.
  38. */
  39. public function run()
  40. {
  41. $uri = $_SERVER['REQUEST_URI'];
  42. $matches = [];
  43.  
  44. switch ($uri) {
  45. case '/':
  46. case '/customer':
  47. require BASE_PATH . '/src/CustomerList.php';
  48. exit();
  49.  
  50. case (preg_match('/^\/customer\/(\d+)$/', $uri, $matches) === 1):
  51. $customerId = $matches[1];
  52. require BASE_PATH . '/src/CustomerView.php';
  53. exit();
  54.  
  55. default:
  56. require BASE_PATH . '/src/404.php';
  57. exit();
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement