Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('BASE_PATH', __DIR__);
- $config = require BASE_PATH . '/config.php';
- $app = new App($config);
- class App
- {
- private $config;
- public function __construct(array $config)
- {
- $this->config = $config;
- }
- public function db()
- {
- if (!isset($this->db)) {
- $host = $this->config['db']['host'];
- $password = $this->config['db']['password'];
- $user = $this->config['db']['user'];
- $dbname = $this->config['db']['dbname'];
- try {
- $this->db = new PDO("mysql:host=$host;dbname=$dbname", $user, $password);
- } catch (PDOException $e) {
- exit('Error: ' . $e->getMessage());
- }
- }
- return $this->db;
- }
- /**
- * Routes requsts to the correct file.
- */
- public function run()
- {
- $uri = $_SERVER['REQUEST_URI'];
- $matches = [];
- switch ($uri) {
- case '/':
- case '/customer':
- require BASE_PATH . '/src/CustomerList.php';
- exit();
- case (preg_match('/^\/customer\/(\d+)$/', $uri, $matches) === 1):
- $customerId = $matches[1];
- require BASE_PATH . '/src/CustomerView.php';
- exit();
- default:
- require BASE_PATH . '/src/404.php';
- exit();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement