forked from jwheare/Borax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
executable file
·177 lines (157 loc) · 6.22 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
HELLO WORLD:
// app/route.class.php
<?php
namespace App;
class Route {
static function getPatterns () {
return array(
'/^$/' => 'home',
);
}
}
// app/controller
<?php
namespace App\Controller;
use Core\Controller;
class HomeHtml extends Controller\Html {
public function index () {
$this->title = "My First Borax Page";
$this->message = "Hello World";
return $this->response;
}
}
// app/template/home/index.tpl.php
<html>
<head>
<title><?php out($this->title); ?></title>
</head>
<body>
<?php out($this->message); ?>
</body>
</html>
Now install apache-vhost.conf, fix the paths, restart apache and go!
ARCHITECTURE:
1. Apache rewrites all URLs to public/index.php
2. index.php creates a web app runner (Core\Web) and calls handleRequest();
3. App runner a) creates a dispatcher (Core\Dispatcher) with the app (App\Route) and base url routes
b) encapsulates the HTTP request $request (Core\Request)
c) encapsulates a user session (App\Session) and injects it into the request
d) calls processRequest($request) on the dispatcher
4. Dispatcher maps the request to a controller (App\Controller) and calls generateResponse() on it
5. Controller either a) renders a template and returns a response (Core\Response)
or b) throws an error or redirect (Core\HttpStatus)
6. Dispatcher returns a response (Core\Response), converting error or redirect if needed first.
7. App runner calls respond() on the response.
8. Response sets headers and echos output.
FILE OVERVIEW:
apache-vhost.conf // apache virtualhost configuration
stub/ // Minimal stub app
app/ // Full example app
|
|-- conf/ // Conf
| --- conf.php // global conf
| --- local.conf.php // local host specific conf. rename this to your system hostname, followed by ".conf.php"
|
|-- controller/ // Controllers
| --- home.controller.php // GET / - home page
| --- signout.controller.php // GET /signout - deletes session cookie and throws a redirect
| --- twitter.controller.php // GET /twitter/start - throws a redirect to start twitter oauth process
| // GET /twitter/callback - handles twitter oauth callback, signs in, redirects
|
|-- init.php // App setup/service registration
|
|-- lib/ // Lib directory on include path for app specific libs
| --- date.class.php // Misc date helpers
|
|-- model/ // Models
| --- person.class.php // Person database model
|
|-- route.class.php // Url routes
|
|-- schema/ // Model database schemas
| --- person.mysql.sql // Person table schema
|
|-- script/ // Script classes that extend Core\Script
|-- twitterinfo.class.php // Looks up twitter user info, optionally authenticated with a user, or manual credentials
|
|-- service/ // Services
| --- db.service.php // mysql database
| --- memcache.service.php // memcache client
| --- memcached.service.php // memcached client (alternate)
|
|-- session.class.php // User sessions
|
|-- template/ // Templates
| --- error.tpl.php // http errors
| --- footer.inc.tpl.php // global footer
| --- header.inc.tpl.php // global header
| --- home/
| --- index.tpl.php // home page
| --- _page/ // page templates with no controller
| --- about.tpl.php // about page
script/ // script runners
|-- twitterinfo.php // runs the app script class
|-- initdb.php // runs the core script class
util.php // global php helper functions
core/ // Core framework classes
|
|-- controller/ // Abstract controllers
| --- base.class.php // Base
| --- form.class.php // Form (POST) -> must redirect
| --- html.class.php // HTML (GET)
| --- json.class.php // Base JSON
| --- jsondelete.class.php
| --- jsonget.class.php
| --- jsonpost.class.php
| --- jsonput.class.php
| --- page.class.php // Static html page (GET)
| --- shared.class.php // Shared logic
|
|-- db.class.php // PDO wrapper
|
|-- dispatcher.class.php // Maps urls to controllers, passing in request objects and returning responses
|
|-- dump.class.php // Debug dump helper
|
|-- email.class.php // mb_send_mail wrapper with templating.
| // writes to mail.log instead of sending if define(DISABLE_EMAILS, true);
|
|-- httprequest.class.php // curl wrapper
|
|-- httpstatus/ // HTTP status classes
| --- base.class.php
| --- baseerror.class.php
| --- baseredirect.class.php
| --- ... // Individual status classes
|
|-- model.class.php // ORM
|
|-- relationshipcache.class.php // Foreign key lookup cache
|
|-- request.class.php // Incoming HTTP request wrapper
| // Wraps $_GET $_POST $_COOKIE and $_SERVER
|
|-- response/ // Response classes
| --- base.class.php
| --- html.class.php
| --- htmlerror.class.php
| --- json.class.php
| --- jsonerror.class.php
| --- redirect.class.php
|
|-- script.class.php // Script class, with helpers for handling command line args
|-- initdbscript.class.php // Creates a new database and username
|
|-- servicemanager.class.php // Static global services manager
|
|-- session.class.php // Base Session class. Wraps $_SESSION. Manages cache headers
|
|-- twitter.class.php // Twitter API client
|
|-- url.class.php // URL encoding, building, parsing class
|
|-- web.class.php // Web app runner
init.php // Framework initialisation
# Web document root
public/ // Put non static and non framework files in here
|-- index.php // Delegates to web app runner