Skip to content

Commit e894a38

Browse files
committed
Create view
1 parent 5075a28 commit e894a38

File tree

12 files changed

+102
-20
lines changed

12 files changed

+102
-20
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App/Classes/Home.php

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
6+
use App\View;
7+
8+
class HomeController
9+
{
10+
public function index():string
11+
{
12+
return (new View('index'))->render();
13+
}
14+
15+
public function upload()
16+
{
17+
$filePath= STORAGE_PATH.'/'.$_FILES['recipt']['name'];
18+
move_uploaded_file($_FILES['recipt']['tem_name'] , $filePath);
19+
20+
echo '<pre>';
21+
var_dump(pathinfo($filePath));;
22+
echo '</pre>';
23+
}
24+
}

src/App/Classes/Invoice.php renamed to src/App/Controllers/InvoiceController.php

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

3-
namespace App\Classes;
3+
namespace App\Controllers;
44

5-
class Invoice
5+
class InvoiceController
66
{
77
public function index(): string
88
{
9-
return 'Invoice';
9+
return 'InvoiceController';
1010
}
1111
public function create(): string
1212
{

src/App/RouteNotFoundException.php renamed to src/App/Exception/RouteNotFoundException.php

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

3-
namespace App;
3+
namespace App\Exception;
44

55
class RouteNotFoundException extends \Exception
66
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Exception;
4+
5+
class ViewNotFoundException extends \Exception
6+
{
7+
protected $message='View Not Found';
8+
public function __construct()
9+
{
10+
}
11+
}

src/App/Router.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
declare(strict_types=1);
33
namespace App;
4+
use App\Exception\RouteNotFoundException;
5+
46
class Router
57
{
68
private array $routes;

src/App/View.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use App\Exception\ViewNotFoundException;
6+
7+
class View
8+
{
9+
10+
/**
11+
* @param string $string
12+
*/
13+
public function __construct(
14+
protected string $view ,
15+
protected array $params =[]
16+
){
17+
}
18+
19+
public function render(): string
20+
{
21+
$filePath=VIEW_PATH.'/'.$this->view.'.php';
22+
if(!file_exists($filePath)){
23+
throw new ViewNotFoundException();
24+
}
25+
26+
ob_start();
27+
include $filePath;
28+
return (string) ob_get_clean();
29+
}
30+
}

src/public/index.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<?php
2+
session_abort();
23
require_once __DIR__."/../../vendor/autoload.php";
4+
define('STORAGE_PATH', __DIR__.'/../storage');
5+
define('VIEW_PATH', __DIR__.'/../views');
6+
37
$router= new App\Router();
48
$router
5-
->get('/', [App\Classes\Home::class,'index'])
6-
->get('/invoice', [App\Classes\Invoice::class,'index'])
7-
->get('/invoice/create', [App\Classes\Invoice::class,'create'])
8-
->post('/invoice/create', [App\Classes\Invoice::class,'create']);
9+
->get('/', [App\Controllers\HomeController::class,'index'])
10+
->get('/invoice', [App\Controllers\InvoiceController::class,'index'])
11+
->get('/invoice/create', [App\Controllers\InvoiceController::class,'create'])
12+
->post('/invoice/create', [App\Controllers\InvoiceController::class,'create']);
913

1014

11-
echo $router->resolve($_SERVER['REQUEST_URI'], strtolower($_SERVER['REQUEST_METHOD']));
15+
echo $router->resolve(
16+
$_SERVER['REQUEST_URI'],
17+
strtolower($_SERVER['REQUEST_METHOD'])
18+
);

src/views/index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<form action="/upload" method="post" enctype="multipart/form-data>">
2+
<input type="file"name="recipt">
3+
<button type="submit">Upload</button>
4+
5+
</form>
6+
<?php

0 commit comments

Comments
 (0)