Download the PHP package dupot/static-management-framework without Composer
On this page you can find all versions of the php package dupot/static-management-framework. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dupot/static-management-framework
More information about dupot/static-management-framework
Files in dupot/static-management-framework
Package static-management-framework
Short Description framework to manage static website
License LGPL-3.0-only
Homepage https://www.dupot.org
Informations about the package static-management-framework
Why?
Static websites are fast, secure and cheap to host. But at some point you need a few dynamic pages to manage them: a login form, an editor for your news, a button that regenerates the siteβ¦
Pulling in a full-stack framework for that is overkill. Dupot Static Management Framework gives you exactly what you need, and nothing more:
- πͺΆ Lightweight: about ten small classes, zero dependencies. You can read the whole source code in 10 minutes.
- π§ Regex routing in JSON: declare your routes in a single
routing.jsonfile. Captured groups are passed as arguments to your methods. - π§© Simple page controllers: extend
PageAbstractand get the request, response and configuration injected automatically. - π¨ Plain PHP templates:
LayoutandViewuse native PHP files, with no template language to learn. - βοΈ INI configuration: load your settings from
.inifiles and override them at runtime. - π Session helpers: read and write GET / POST / SESSION / SERVER values through one
Requestobject. - π€ Companion of dupotStaticGenerationFramework: generate your site with one, manage it with the other.
Table of contents
- Installation
- Quick start
- Routing
- Pages
- Layouts and views
- Configuration
- Request and response
- Architecture
- License
Installation
Requirements: PHP β₯ 7.2. No other dependencies.
Quick start
Here is the target project structure:
1. Autoload your own code
Add your namespace to your project's composer.json, then run composer dump-autoload:
2. Create the front controller
File: public/index.php
3. Declare your routes
File: src/conf/routing.json
4. Run it
Open http://localhost:8000 and you're done π
Routing
Each route is a JSON object with three fields:
| Field | Description |
|---|---|
pattern |
A PCRE regular expression, with delimiters, tested on the URL path. |
class |
The fully qualified class name of the page to instantiate. |
method |
The method to call on that page. |
Routes are tested in order and the first match wins. If no route matches, the application answers 404.
Captured groups are passed as method arguments. That makes routes with parameters easy:
π‘ Anchor your patterns with
^and$. A pattern like#/#matches every URL.
Pages
A page is a class that extends PageAbstract. Before your method is called, the framework injects the Request, the Response and the ConfigManager, then calls the before() hook. Override before() for shared logic such as an authentication check.
File: src/Infrastructure/Pages/HomePage.php
File: src/Infrastructure/Pages/AboutPage.php
Example: protecting your pages
Layouts and views
Layouts and views are plain PHP files. The variables you pass are available in $this->contextList.
Layout::assignContext($key, $value)sets a value.Layout::appendContext($key, $value)adds a value to a list, which is useful for stacking several views.
File: src/Infrastructure/Pages/Layout/default.php
File: src/Infrastructure/Pages/View/home.php
File: src/Infrastructure/Pages/View/about.php
Configuration
ConfigManager loads INI files (with sections) and lets you add values at runtime:
getSectionParam() throws an exception if the parameter doesn't exist, so a missing setting never goes unnoticed.
Request and response
| Method | Description |
|---|---|
getPostParam($name) |
POST value. Throws if missing. |
getPostParamOr($name, $default) |
POST value, or the default. |
getPostParamList() / getGetParamList() |
All POST / GET values. |
getSessionParam($name) / getSessionParamOr($name, $default) |
Session value. |
setSessionParam($name, $value) |
Writes to the session (and $_SESSION). |
isMethodGet() / isMethodPost() |
Tests the HTTP method. |
getUrl() |
Path of the requested URL. |
Response::redirect($url) |
HTTP redirection. |
Architecture
| Class | Role |
|---|---|
Application |
Dispatches the request to the right page |
Setup\RouteManager |
Loads routes and matches URLs |
Setup\ConfigManager |
Manages INI configuration |
Http\Request |
Wraps GET / POST / SESSION / SERVER |
Http\Response |
Redirections |
Page\PageAbstract |
Base class for your pages |
Render\Layout |
Page template |
Render\View |
Content fragment |
Contributing
Issues and pull requests are welcome on GitHub.
License
Released under the LGPL-3.0 license. Created by Michael Bertocchi.