1
1
diff --git a/bootstrap.php b/bootstrap.php
2
- index 52faebf..986f2f4 100644
2
+ index 52faebf..fa4ccc1 100644
3
3
--- a/bootstrap.php
4
4
+++ b/bootstrap.php
5
- @@ -2,3 +2,88 @@
5
+ @@ -2,3 +2,86 @@
6
6
7
7
require __DIR__.'/vendor/autoload.php';
8
8
@@ -17,30 +17,36 @@ index 52faebf..986f2f4 100644
17
17
+ * *************** Our one-method framework
18
18
+ */
19
19
+
20
- + function _run_app(Container $c) {
20
+ + function _run_app(Request $request) {
21
+ + $c = _create_container();
22
+ +
23
+ + // include the routing and controllers
24
+ + require_once 'routing.php';
25
+ + require_once 'controllers.php';
26
+ +
21
27
+ // run the framework!
22
28
+ $route = $c['router']->match(
23
- + $c[' request'] ->getPathInfo(),
24
- + $c[' request'] ->server->all()
29
+ + $request->getPathInfo(),
30
+ + $request->server->all()
25
31
+ );
26
32
+
27
33
+ // merge the matched attributes back into Symfony's request
28
34
+ if ($route) {
29
- + $c[' request'] ->attributes->add($route->params);
35
+ + $request->attributes->add($route->params);
30
36
+ }
31
37
+
32
38
+ // get the "controller" out, or default to error404_controller
33
- + $controller = $c[' request'] ->attributes->get('controller', 'error404_controller');
39
+ + $controller = $request->attributes->get('controller', 'error404_controller');
34
40
+
35
41
+ if ($controller == 'error404_controller') {
36
- + $msg = sprintf('Controller not found for "%s"', $c[' request'] ->getPathInfo());
42
+ + $msg = sprintf('Controller not found for "%s"', $request->getPathInfo());
37
43
+ $c['logger']->err($msg);
38
44
+ } else {
39
45
+ $c['logger']->info(sprintf('Found controller "%s"', $controller));
40
46
+ }
41
47
+
42
48
+ // execute the controller and get the response
43
- + $response = call_user_func_array($controller, array($c[' request'] , $c));
49
+ + $response = call_user_func_array($controller, array($request, $c));
44
50
+ if (!$response instanceof Response) {
45
51
+ throw new Exception(sprintf('Your controller "%s" did not return a response!!', $controller));
46
52
+ }
@@ -52,45 +58,38 @@ index 52faebf..986f2f4 100644
52
58
+ * *************** Container Setup
53
59
+ */
54
60
+
55
- + $c = new Container();
56
- +
57
- + // configuration
58
- + $c['connection_string'] = 'sqlite:'.__DIR__.'/data/database.sqlite';
59
- + $c['log_path'] = __DIR__.'/data/web.log';
60
- +
61
- + // Service setup
62
- + $c['connection'] = function(Container $c) {
63
- + return new PDO($c['connection_string']);
64
- + };
61
+ + function _create_container()
62
+ + {
63
+ + $c = new Container();
65
64
+
66
- + $c['request'] = function() {
67
- + return Request::createFromGlobals() ;
68
- + } ;
65
+ + // configuration
66
+ + $c['connection_string'] = 'sqlite:' . __DIR__ . '/data/database.sqlite' ;
67
+ + $c['log_path'] = __DIR__ . '/data/web.log' ;
69
68
+
70
- + $c['router'] = function() {
71
- + $routerFactory = new RouterFactory();
69
+ + // Service setup
70
+ + $c['connection'] = function (Container $c) {
71
+ + return new PDO($c['connection_string']);
72
+ + };
72
73
+
73
- + $router = $routerFactory->newInstance();
74
+ + $c['router'] = function () {
75
+ + $routerFactory = new RouterFactory();
76
+ + $router = $routerFactory->newInstance();
74
77
+
75
- + // create a router, build the routes, and then execute it
76
- + $router->add('attendees_list', '/attendees')
77
- + ->addValues(['controller' => 'attendees_controller']);
78
- + $router->add('homepage', '{/name}')
79
- + ->addValues(['controller' => 'homepage_controller']);
78
+ + return $router;
79
+ + };
80
+ + $c['logger_writer'] = function (Container $c) {
81
+ + return new Stream($c['log_path']);
82
+ + };
83
+ + $c['logger'] = function (Container $c) {
84
+ + $logger = new Logger();
85
+ + $logger->addWriter($c['logger_writer']);
80
86
+
81
- + return $router;
82
- + };
83
- + $c['logger_writer'] = function(Container $c) {
84
- + return new Stream($c['log_path']);
85
- + };
86
- + $c['logger'] = function(Container $c) {
87
- + $logger = new Logger();
88
- + $logger->addWriter($c['logger_writer']);
87
+ + return $logger;
88
+ + };
89
89
+
90
- + return $logger;
91
- + };
92
- +
93
- + return $c;
90
+ + return $c;
91
+ + }
92
+ \ No newline at end of file
94
93
diff --git a/controllers.php b/controllers.php
95
94
new file mode 100644
96
95
index 0000000..9adb562
@@ -147,15 +146,15 @@ index 0000000..9adb562
147
146
+ return $response;
148
147
+ }
149
148
diff --git a/index.php b/index.php
150
- index 919eee1..dd22794 100644
149
+ index 919eee1..2064c68 100644
151
150
--- a/index.php
152
151
+++ b/index.php
153
- @@ -1,121 +1,8 @@
152
+ @@ -1,121 +1,9 @@
154
153
<?php
155
154
- require __DIR__.'/bootstrap.php';
156
155
157
156
- // create a request object to help us
158
- - use Symfony\Component\HttpFoundation\Request;
157
+ use Symfony\Component\HttpFoundation\Request;
159
158
- use Symfony\Component\HttpFoundation\Response;
160
159
- use Aura\Router\RouterFactory;
161
160
- use Pimple\Container;
@@ -213,7 +212,7 @@ index 919eee1..dd22794 100644
213
212
-
214
213
- // get the "controller" out, or default to error404_controller
215
214
- $controller = $c['request']->attributes->get('controller', 'error404_controller');
216
- -
215
+
217
216
- if ($controller == 'error404_controller') {
218
217
- $msg = sprintf('Controller not found for "%s"', $c['request']->getPathInfo());
219
218
- $c['logger']->err($msg);
@@ -226,11 +225,10 @@ index 919eee1..dd22794 100644
226
225
- if (!$response instanceof Response) {
227
226
- throw new Exception(sprintf('Your controller "%s" did not return a response!!', $controller));
228
227
- }
229
- + $c = require __DIR__.'/bootstrap.php';
230
- + require 'routing.php';
231
- + require 'controllers.php';
228
+ + require __DIR__.'/bootstrap.php';
232
229
233
- + $response = _run_app($c);
230
+ + $request = Request::createFromGlobals();
231
+ + $response = _run_app($request);
234
232
$response->send();
235
233
-
236
234
- /*
0 commit comments