akshaykhale1992 /
TinyPHP
| 1 | <?php |
||||
| 2 | |||||
| 3 | /** |
||||
| 4 | * Loading composer Libraries |
||||
| 5 | */ |
||||
| 6 | require __DIR__ .'/../vendor/autoload.php'; |
||||
| 7 | |||||
| 8 | |||||
| 9 | /** |
||||
| 10 | * Loading the Environment |
||||
| 11 | * setting option |
||||
| 12 | */ |
||||
| 13 | $dotenv = new Dotenv\Dotenv(__DIR__.'/../'); |
||||
| 14 | $dotenv->load(); |
||||
| 15 | |||||
| 16 | /** |
||||
| 17 | * Loading main Controller Class and |
||||
| 18 | * helpers file to load helper function |
||||
| 19 | * and to load Controller |
||||
| 20 | * Once can skip helpers file if |
||||
| 21 | * don't want the helper functions |
||||
| 22 | * in the framework. |
||||
| 23 | */ |
||||
| 24 | require __DIR__.'/../helpers.php'; |
||||
| 25 | |||||
| 26 | require __DIR__.'/../'.getenv('CONTROLLERS_DIRECTORY','controllers').'/Controller.php'; |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 27 | $paths = array(__DIR__ .'/../'.getenv('VIEWS_DIRECTORY','views')); |
||||
| 28 | $cache_path = array('cache_path' => __DIR__ .'/../'.getenv('CACHE_DIRECTORY','cache')); |
||||
| 29 | |||||
| 30 | $path = explode('/', trim(strtolower($_SERVER['REQUEST_URI']), '/')); |
||||
| 31 | $path[count($path)-1] = explode('?', end($path))[0]; // Removing get parameters from the Request URL |
||||
| 32 | |||||
| 33 | $default_pages = ['index','home','default']; //Default pages of the website |
||||
| 34 | |||||
| 35 | if (empty($path[0]) || in_array($path[0], $default_pages)) { |
||||
| 36 | $method = 'index'; // Loading default index method from the controller for homepage |
||||
| 37 | } else { |
||||
| 38 | $method = implode('_', $path); // Calling method from the URL |
||||
| 39 | } |
||||
| 40 | |||||
| 41 | $controller = new Controller($paths, $cache_path); |
||||
| 42 | if (method_exists($controller, $method)) { |
||||
| 43 | echo $controller->{ $method }(); // Calling the method from the Controller |
||||
| 44 | } else { |
||||
| 45 | echo $controller->notFound(); // Calling 404 Page if method not found |
||||
|
0 ignored issues
–
show
Are you sure
$controller->notFound() of type View can be used in echo? Consider adding a __toString()-method.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 46 | } |
||||
| 47 | |||||
| 48 | exit(); |
||||
| 49 |