Skip to content

Commit a2fb493

Browse files
committed
initial commit
0 parents  commit a2fb493

File tree

7 files changed

+214
-0
lines changed

7 files changed

+214
-0
lines changed

.htaccess

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RewriteEngine on
2+
RewriteCond %{REQUEST_FILENAME} !-f
3+
RewriteCond %{REQUEST_FILENAME} !-d
4+
RewriteRule ^(.*) index.php?url=$1 [L,QSA]

Engine/App.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Engine;
4+
5+
/**
6+
* Class App
7+
* @package Engine
8+
*/
9+
final class App {
10+
/**
11+
* @var
12+
*/
13+
public static $controller;
14+
public static $defaultController = 'index';
15+
public static $action;
16+
public static $defaultAction = 'index';
17+
18+
/**
19+
* App constructor.
20+
*/
21+
public function __construct() {
22+
}
23+
24+
public static function start(): void {
25+
spl_autoload_register(array('\Engine\App', 'autoload'));
26+
27+
28+
static $run;
29+
if ($run === TRUE) return;
30+
31+
Request::setup();
32+
33+
$controller = Request::getController() . '_controller';
34+
//utworzenie kontrolera
35+
self::$controller = new $controller();
36+
// tworzymy obiekt refleksji klasy
37+
$class = new ReflectionClass(self::$controller);
38+
//pobieramy metodę
39+
$method = $class->getMethod(URI::getAction());
40+
//wykonanie metody z argumentami URI
41+
$method->invokeArgs(self::$controller, URI::getArguments());
42+
$run = TRUE;
43+
44+
45+
}
46+
47+
48+
/**
49+
* @param string $class_name
50+
*/
51+
public static function autoload(string $class_name): void {
52+
$class = str_replace('_', '/',
53+
str_replace('\\', '/', $class_name)
54+
);
55+
56+
if (empty($class)) {
57+
return;
58+
}
59+
require_once(APP_PATH . $class . '.php');
60+
61+
}
62+
63+
64+
}

Engine/Controller.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Engine;
4+
5+
6+
class Controller {
7+
8+
9+
public function render(){
10+
11+
}
12+
}

Engine/Request.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
namespace Engine;
4+
5+
/**
6+
* Class Request
7+
* @package Engine
8+
*/
9+
class Request {
10+
11+
12+
/**
13+
* @var
14+
*/
15+
protected static $array;
16+
/**
17+
* @var
18+
*/
19+
protected static $controller;
20+
/**
21+
* @var
22+
*/
23+
protected static $action;
24+
/**
25+
* @var
26+
*/
27+
protected static $arguments;
28+
/**
29+
* @var
30+
*/
31+
protected static $path;
32+
33+
/**
34+
*
35+
*/
36+
public static function setup() {
37+
38+
self::$path = $_SERVER['REQUEST_URI'];
39+
40+
41+
self::$array = explode('/', trim(self::$path, '/'));
42+
43+
self::$controller = self::$array[0] ?? App::$defaultController;
44+
self::$action = self::$array[1] ?? App::$defaultAction;
45+
var_dump(Request::getArray());
46+
}
47+
48+
/**
49+
* @return array
50+
*/
51+
public static function getArray(): array {
52+
return self::$array;
53+
}
54+
55+
/**
56+
* @param array $array
57+
*/
58+
public static function setArray(array $array): void {
59+
self::$array = $array;
60+
}
61+
62+
/**
63+
* @return string
64+
*/
65+
public static function getController(): string {
66+
return self::$controller;
67+
}
68+
69+
/**
70+
* @param string $controller
71+
*/
72+
public static function setController(string $controller): void {
73+
self::$controller = $controller;
74+
}
75+
76+
/**
77+
* @return string
78+
*/
79+
public static function getAction(): string {
80+
return self::$action;
81+
}
82+
83+
/**
84+
* @param string $action
85+
*/
86+
public static function setAction($action): void {
87+
self::$action = $action;
88+
}
89+
90+
/**
91+
* @return array
92+
*/
93+
public static function getArguments(): array {
94+
return self::$arguments;
95+
}
96+
97+
/**
98+
* @param string $arguments
99+
*/
100+
public static function setArguments($arguments): void {
101+
self::$arguments = $arguments;
102+
}
103+
104+
/**
105+
* @return string
106+
*/
107+
public static function getPath(): string {
108+
return self::$path;
109+
}
110+
111+
/**
112+
* @param string $path
113+
*/
114+
public static function setPath($path): void {
115+
self::$path = $path;
116+
}
117+
}

application/controller/Hello.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Application;
4+
5+
class Hello extends \Engine\Controller {
6+
public function index(){
7+
8+
}
9+
}

bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
define('APP_PATH', $_SERVER['DOCUMENT_ROOT'].'/');
4+

index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
require_once 'bootstrap.php';
3+
require_once 'Engine/App.php';
4+
Engine\App::start();

0 commit comments

Comments
 (0)