Skip to content

Commit 381786c

Browse files
committed
working after episode 30 php autoloading and extractions 5 22 51
1 parent 622987e commit 381786c

File tree

9 files changed

+24
-13
lines changed

9 files changed

+24
-13
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

router.php renamed to Core/router.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
$routes = require('routes.php');
3+
$routes = require(base_path('routes.php'));
44

55
$uri = parse_url($_SERVER['REQUEST_URI'])['path'];
66

@@ -9,7 +9,8 @@
99
function routeToController($uri, $routes)
1010
{
1111
if (array_key_exists($uri, $routes)) {
12-
require $routes[$uri];
12+
// dd($routes[$uri]);
13+
require base_path($routes[$uri]);
1314
} else {
1415
abort();
1516
}

controllers/notes/create.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require base_path('Validator.php');
3+
require base_path('Core/Validator.php');
44

55
$config = require(base_path('config.php'));
66
$db = new Database($config['database']);

public/index.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@
99
// const BASE_PATH = __DIR__ . '/../';
1010
const BASE_PATH = __DIR__ . '/../';
1111

12-
require BASE_PATH . 'functions.php';
13-
require base_path('Database.php');
14-
require base_path('Response.php');
15-
require base_path('router.php');
12+
require BASE_PATH . 'Core/functions.php';
13+
14+
// when class is not found, this function will be called
15+
// this thing autoload classes on demand
16+
// it lets us declare manually how we wanna go about importing classes
17+
// that has not already been explicitly or manually required/imported
18+
spl_autoload_register(function ($class) {
19+
// dd($class);
20+
require(base_path("Core/{$class}.php"));
21+
});
22+
23+
// require base_path('Database.php');
24+
// require base_path('Response.php');
25+
require base_path('Core/router.php');
1626

1727

1828

views/403.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<?php require('views/partials/head.php'); ?>
2-
<?php require('views/partials/nav.php'); ?>
1+
<?php view('partials/head.php'); ?>
2+
<?php view('partials/nav.php'); ?>
33
<main>
44
<div class="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8">
55
<h1 class="text-2xl font-bold">403 Unauthorized. You are not authorized to view this page.</h1>
@@ -8,4 +8,4 @@
88
</p>
99
</div>
1010
</main>
11-
<?php require('views/partials/footer.php'); ?>
11+
<?php view('partials/footer.php'); ?>

views/404.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<?php require('views/partials/head.php'); ?>
2-
<?php require('views/partials/nav.php'); ?>
1+
<?php view('partials/head.php'); ?>
2+
<?php view('partials/nav.php'); ?>
33
<main>
44
<div class="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8">
55
<h1 class="text-2xl font-bold">404 Not Found</h1>
@@ -8,4 +8,4 @@
88
</p>
99
</div>
1010
</main>
11-
<?php require('views/partials/footer.php'); ?>
11+
<?php view('partials/footer.php'); ?>

0 commit comments

Comments
 (0)