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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
## x-anom
### X is ANOther Mvc
x-anom is an Object-Oriented MVC php-framework.
Main advantages of the framework:
* It is super-light and fast;
* Core has almost zero dependences and contains almost anything you need to start and optimize a server-based web-application.
* It is extensible especialy if you use Composer (which is recommended, though not required)
* Handles security; and as long as you write code using secure practices, it will be secure
* It's easy to configure, easy to code, easy to use
### Requirements
* PHP 8+
* Some webserver (Apache/Nginx)
* Some SQL server (MySQL/MariaDB/Postgress)
* Basic knowledge of php and SQL
* Baasic knowlege of OOP
### Code standards
Amon uses the PSR-1 code standard with a few enchansements:
Controllers are named like
class SomeController
// or...
class SomeController_something
where ```something``` indicates some special operational role of the contoller
ex. ```_user```, ```_service```, ```manager``` etc
As a result all model classes are suffixed with ```_model```:
class SomeModelName_model;
### What is included
Core components:
#### Router
Routes request to the appropriate Controller
- matches static paths
- matches dynamic paths through regex expressions
- takes care of request-method
#### Controller and Model
(just write your Controller and Model classes)
#### View (rendering engine)
Usually you just need to call the render_view(template, data) function.
For templating we use the php short-tag syntax.
main functions:
* load_template( template, data)
* render_view( view_file , data )
* load_asset( type, assets_array )
* set_headers( content_type, ttl, more_array )
* render_text( data, content_type, ttl )
* reply_json( data, ttl )
#### Class autoloader
Composer is recomende;
but if is not available this one will do the job
#### Caching
* File Caching mechanism
* Redis Cache
* Memcached Caching
#### Session Management
* DefaultSession: psevdo-handler with passthrough methods
* FileSession: custom file-based session handler
* DatabaseSession: database session handler
#### More
* Proxy design pattern
* Error handling
* Repository
* Cli interface (*summarizes anom*)
### Other features
* Docker ready
You can run the framework as is in a Docker environment;
Also. you can edit just a bit the configuration files to customize the project
to support various technologies; Check the README file in the project's root
folder to find out more.
### What is not included
* It lacks a query builder (SQL is easy and very powerful); do not forget to use prepared statements for all your SQL queries.
* TODO: User-Role based administration class.
* TODO: Shoping-Cart class.
## Life (and death) of a Client_Request–Server_reply session
1. THE REQUEST: client makes a request -> request arives to the server -> .htaccess sends the request to the index.php
2. index loads Configuration (constants.php + config.php) and AUTOLOADER in order load classes easily
3. index loads init.php -> after initialization the APP is READY -> index loads the routes; Route::run() -> the APP is RUNNING
4. Router resolves the request pattern and calls a Controller
5. (if needed) Controller asks data from the Model; then responds a reply to the client using **render** functions -> APP dies
## Direcrtory structure
NOTE: directory structure needs updata, but the main structure ramains untouched.
.
|-- container * for docker/container configuration
| |-- bin * scripts
| `-- config * settings
|
|-- core * core code
| |-- auth * authentication and credentials
| |
| |-- config * application parametres
| | |-- config.php
| | |-- constants.php
| | |-- credentials.php
| | `-- init.php
| |
| |-- classes * core classes
| | |-- cacher
| | |-- Benchmark.php
| | |-- Database.php
| | |-- Route.php
| | |-- Security.php
| | `-- Session.php
| |
| `-- helpers * core helpers
| |-- autoload.php
| |-- error-handling.php
| `-- render.php
|
|-- data * folder for batch data-imports to database
|
|-- public ** PUBLIC directory
| |-- app * APP
| | |-- Controllers * Controllers
| | | |-- Art.php
| | | `-- ...
| | |
| | |-- Models * Models
| | | |-- Art_model.php
| | | `-- ...
| | |
| | |-- Views * Views
| | | |-- group.php
| | | `-- item.php
| | |
| | `-- routes.php * application routes
| |
| `-- cache * Caching folder
|
`-- vendor * Vendor classes and autoloader
|-- composer
`-- ...
## Naming Conventions and good practices
1. Keep Controllers, Models, Views in their folders
2. Organize View elements in subfolders
3. Controller and Model names shall be camelcased;
- fist letter should be Uppercase;
- classes shall be named exactly as their filenames
4. Model names shall be suffixed with _model
5. Comment every-single Controller/Model/class and comment every method
6. On Views (php templates) use php short-tags when possible
- Views are about rendering data; avoid complex-logic
- [if/else], [foreach] and some flag/temp [variables] sould be fair enough
7. All of the above rules are strongly recommended (although not obligatory);
## Notes and brainstorming
### for template system check
https://css-tricks.com/php-is-a-ok-for-templating/
### for rendering system you may check volt too
https://docs.phalcon.io/4.0/en/volt
## Brainstorming
* take care of various hacks
chk: https://stackoverflow.com/questions/1996122/how-to-prevent-xss-with-html-php
* HTML to MarkDown!
chk: https://github.com/thephpleague/html-to-markdown
VIEW data
-> ceo -> title
-> description
-> keywords
-> ...
-> content -> view : view_filename
-> key : some_variable_name
-> data : the_data
## Knowledge Requirements
## Tools of work
None of the following tools is necessary, but they will help very very-much.
- Composer
- Docker
- Code editor
- Coffee + Nicotine
|