Just a try to make really fast and light (and stupid) framework.
- MVC- or MVMC-architecture (first M - Model or Module, second M - Middleware)
- Modular structure with very lightweight core
- Filesystem-based routing
- Auto HTML escaping of the data for views by default
- Minimum of OOP
- Lazy-load of everything
app
- an application directoryapp/config
- configuration filesapp/config/db.php
- a database configapp/config/paths.php
- a paths configapp/controllers
- controllers. Controllers paths are defining routes (see below Routing).app/controllers/_404.php
- 404 pageapp/controllers/_default.php
- a controller for "/". Basically it is optional file.app/middlewares
- middlewares (see below Middlewares).app/views
- templatesapp/custom.php
- a place for the app-wide codeapp/modules
- modules/modelss
- a directory for static files. Can be changed in the "paths" config.system
- core filessystem/core.php
- the core (see below Core)system/PicoDatabase
- SQL query builder and MySQLi wrapperindex.php
- entry point
All files from the list above are required. There are also other files (modules, middlewares, etc.), which just contain some sample code.
Framework takes a route from a config "paths", an element "ROUTE". Then it searches for the appropriate controller. Better to explain by an example. Let's ROUTE = /hello/world/123
. Then it will try to include files in the following order:
-
app/controllers/hello/world/123.php
-
app/controllers/hello/world/123/_default.php
-
app/controllers/hello/world._QPARAM.php
"123" will be put in$_QPARAM
variable (in controller's scope). -
app/controllers/hello/world/_default._QPARAM.php
. QParam mechanism will work similarly to the point 3. -
app/controllers/hello._QPARAM.php
. Similarly to the point 3, but$_QPARAM
will be equal to "world/123". -
app/controllers/hello/_default._QPARAM.php
. Similarly to the point 5. -
app/controllers/_default._QPARAM.php
. Similarly to the point 3, but$_QPARAM
will be equal to "hello/world/123".
If the file is not exists, then it will just go to the next point (do not QParam checks). If the file is exists then it will stop anyway (after including the file or by LoadException).
Middleware will be run if it matches to controller name or its part.
For example you can check authentication in /auth middleware, so all /auth/* controllers will be available only for authenticated users.
/_default
middleware will be run at first (if exists) and /_zzz_last
at last (if exists).
A middleware can know which controller is processed from the variable $_QNAME
.
-
processRequest ($query)
. Takes the query and runs an appropriate controller or /_404. It is automatically called from index.php. -
allowIncludeFile ($file)
. Returns true if it is safe toinclude()
$file
. Checks for "../", "/.."" and existing of the$file
. -
getConfig ($name[, $param])
. Loads (justinclude()
s) config fromapp/config
or takes it from the memory and returns it. The config file should look like this:<?php return <something>;
, where<something>
is an array or just some value. -
runController ($route[, $data])
. Runs (justinclude()
s) an appropriate controller by the given route. Processes routing.extract()
s$data
to controller's scope. -
runView ($name[, $data])
. Runs (justinclude()
s) specified view.extract()
s html-escaped$data
to view's scope. -
getDatabaseConnection ()
. Creates and returns new instance (does not use existing) of PicoDatabase. -
getModule ($name[, $data])
. Modules are php files, which should contain class Module_$name. All special characters in$name
will be replaced with "_". That class can extend BaseModule, which just provides $this->DB variable with PicoDatabase instance. Any module object will be created only once, further calls will receive existing instance (like singleton). -
dataRepo ($key[, $val])
. Simple function to store data in the memory. Basically it is used just instead of a global variable. If$val
is specified, then it will store the value. Otherwise it will return stored value (or null). -
dataRepoPush ($key[, $val])
. Simple function to store data in the array in the memory. Basically it is used just instead of a global variable. If$val
is specified, then it will store the value in the array with name$key
. Otherwise it will return stored array with name$key
(or null). -
_U ($q[, $params])
. Returns URL of controller$q
with GET parameters$params
.$params
can be a string or an array. It considers "BASE_URL" from the "paths" config. -
_US ($q)
. Returns URL of the static file$q
. It considers "STATIC_BASE_URL" from the "paths" config. -
htmlEscape ($s)
. Returns$s
with applied htmlspecialchars function. Also works with arrays. This function is automatically applied to$data
inrunView
. -
dontHtmlEscape ($s)
. Returns$s
, which is marked as a value which should not be escaped. -
formatException ($e)
. Returns the exception$e
in human-readable view. Does not use HTML or HTML escaping.