, (*1)
, (*2)
StaticPHP
Simple, modular php framework. README.md needs to be updated., (*3)
Requirements
Installation
There are two ways to start using StaticPHP framework:, (*4)
- Docker <- Suggested one
- Composer
1. Using Docker, (*5)
docker compose build develop
docker compose up -d --remove-orphans develop
- Open in vscode using Remote containers
2. Using composer, (*6)
Run composer create-project 4apps/staticphp ./
for stable version and composer create-project 4apps/staticphp ./ master-dev
for latest development version from github. Composer will install all the dependecies for you., (*7)
How to install composer?, (*8)
Npm for SCSS and Javascript, (*9)
Install node and npm
run npm install
, (*10)
How to install node?, (*11)
* Remember to set correct permissions for Cache directory. For example: chown www-data:www-data ./src/Application/Cache/
or chmod 777 ./src/Application/Cache/
, (*12)
Most quickest way to run your project is to use php's in-built server. To do that, cd into the ./somedir/src/Application/Public and run php -S 0.0.0.0:8081
. Now open your server_ip:8081 (or 127.0.0.1:8081) and StaticPHP first page should show up., (*13)
or, (*14)
run npm start
, (*15)
By default, running StaticPHP with php's cli server, turns debugging on, but you can configure that in ./somedir/Applications/Config/Config.php by setting $config['environment'] or $config['debug'] variables., (*16)
* Take a look at home controller in ./somedir/src/Application/Modules/Controllers/Welcome.php and views in ./somedir/src/Application/Modules/Views/ for basic framework usage., (*17)
Assets
All assets are stored in ./somedir/src/Application/Public/assets/ directory. StaticPHP uses npm to handle css (using SCSS) and js assets, but you can also do it manually., (*18)
Cron
Running controller from command line can be done this way: php -f /srv/sites/gm.lv/sla/src/Application/Public/index.php -- --query /defaults/console/refresh
, (*19)
Api
Api documentation*, (*20)
* Work in progress, (*21)
Example app
A simple todo application based on sessions. To view the source, checkout the "example" branch., (*22)
PHPUnit
To run phpunit tests, install composer dev dependecies (composer install --dev
) and then run ./Vendor/bin/phpunit ./src/Application/
, (*23)
ApiGen api documentation
To generate api documentation, install composer dev dependecies (composer install --dev
), run ./Vendor/bin/apigen generate ./ --destination ./src/Application/Public/docs ./src
or npm run docs
and open http://127.0.0.1:8081/docs/, (*24)
Basic Nginx configuration
server {
listen 80;
listen 443 ssl;
server_name staticphp.gm.lv;
root /www/sites/gm.lv/staticphp/src/Application/Public;
index index.php index.html index.htm;
# Error responses
error_page 403 /errors/E403.html;
error_page 404 405 =404 /errors/E404.html;
error_page 500 501 502 503 504 =500 /errors/E500.html;
# Handle error responses
location ~ /errors/(E[0-9]*.html) {
alias /www/sites/gm.lv/staticphp/System/Modules/Core/Views/Errors/$1;
}
# Base location
location / {
if (!-e $request_filename)
{
rewrite ^(.*)$ /index.php?/$1 last;
}
}
# Allow font origin (for webfonts and similar)
location ~* \.(eot|ttf|woff|svg)$ {
add_header Access-Control-Allow-Origin *;
}
# Set assets expiration headers to max
location ~ ^/assets/ {
expires max;
}
# Handle php files
location ~ \.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include /etc/nginx/fastcgi_params;
# To intercept errors from fastcgi and show our error pages instead, otherwise nginx will send to browser whatever response there was from fastcgi
fastcgi_intercept_errors on;
}
# Show 404 for hidden files
location ~ /\. {
return 404;
}
}
TODO and ideas
- i18n and cache class usage guide
- Cache class: postgres, mysql and sql lite support (who knows, somebody may want this:)
- Write usage guide
- Rewrite all sessions classes into one by adding an option to choose from session backend to use, possibly allowing to use multiple backends (e.g. memcached -> sql).
- Look for a way to extend a view from same directory as the view extending it. E.g. {% extends "layout.html" %} instead of {% extends "Defaults/Views/layout.html" %}
History
v1.2.0
- Tests most probably doesn't work anymore
- Update todo example app
- โ Bring Exceptions to its own folder
- โ Use full namespaces also for Core\Models. For example
use \Core\Models\Router;
now is use \System\Modules\Core\Router;
- โ Update url structure to work without ending slash. Now in templates you do this:
{{ controller_url }}/test-page
instead of - {{ controller_url }}test-page
.
- โ Generate menus and submenus/sidebar using classes
- โ Table presentation class
- โ Update server to PHP 8.1
- โ Update page layout to bootstrap 5
v1.2.0
- โ Moved docker to main repository. Development is now meant to be used remotely in docker.
- โ Moved Application and System folders into src.
- โ Updated everything - PHP 8.1, bootstrap, npm libraries.
- โ Removed redundant npm libraries.
- โ Removed jQuery
- โ Added bump2version.
- โ Added build docker service which creates staticPHP archive.
- โ Moved assets under its own src directory - easier to grep through if its under another parent path than dist folder.
v1.1.0
v1.0.0
- โ Removed Help/Example page descriptions - thats basically what apigen is for.
- โ Rewrite Db class so that in init method $name parameter comes before $config.
- โ Use composer only for php stuff.
- โ Setup SCSS using npm scripts.
- โ Setup webpack for js, also using npm scripts.
- โ Expanded core clases from universal to more specific roles.
- โ Added first PHPUnit tests.
- โ Various Bugfixes.
- โ Allow controllers, helpers and models to also be loaded from Application folder, same as Config already was.
- โ Replaced apigen config file with new format.
v0.9.5
- โ Cache class: Redis, Memcached, APC and files.
- โ i18n class with twig integration (i18n::twigRegister(Load::$config['view_engine'])).
v0.9.4
- โ Fixed possibility of nonexisting variable causing notices.
- โ Updated nginx configuration example.
- โ Added .editorconfig file.
- โ Updated composer dependencies.
- โ Few micro performance updates.
- โ Option to disable twig template engine.
v0.9.3
- โ Fixed issue preventing to load page from subdirectory.
v0.9.2
- โ Fixed issue with $controller_url not being set when default route from Routes.php config file is loaded.
- โ Core controller render method didn't have $data argument, fixed.
- โ siteUrl twig filter now accepts all parameters that Router::siteUrl() does.
- โ Added debug method to Router class.
- โ Made all Router's helper methods public.
- โ Renamed some variables of the Router class, so it makes more sense also added some new ones.
- โ More Router fixes for correct controller handling.
v0.9.1
- โ Documentation config update
v0.9
- โ Added various small helper functions, take a look in System/Modules/Core/Helpers/Other.php
- โ Rewritten framework for more modular structure
- Links like - /module/my-controller/my-method are now turned into Application/Modules/Module/MyController.php::myMethod($params)
- โ PSR-0 or PSR-4 autoloading schema
- All folder names and file names are now named using StudlyCaps
- We are not using "Vendor" in front of autoloading classes to avoid long includes (e.g. "use" parameters), which could be useful if more than one application is run with same instance, but for now we are skipping this.
- โ Added core controller
- If used, controller now have access to self::$controller_url and self::$method_url, very useful for migrating controllers to other urls and for controller copying.
- self::render('path_to_view.html') will automatically look into module's Views directory
- self::write($params) will echo json encoded string if $params is an array
- โ Json reponse has been used very often so far, maybe we should make some kind of output filtering method that outputs content based on output type?
- If an array is returned from a controller method, its turned into a json encoded string and is sent back to the browser
- โ Put helpers under namespaces?
- No, functions should be in global scope
- โ Decide to go with Reflection Api or not.
- โ Css and js minifying - git hooks, also css and js versioning.
- Added minify.py under Scripts, this also makes javascript source maps
- Added all the stuff related to this in default views
- Added git pre-commit hook that can check whether css, js file was modified and based on that execute minify.py
- Added git post-receive hook that can check whether css or js file was modified and base on that increase css or js version by calling a url with wget
- โ Script to clear Twig cache. Also a git hook?
- Added a git post-receive script that can check whether any html file was modified, and if was, can clear twig cache
v0.8
- โ Should database run all queries in beginTransaction .. commit .. rollback mode?
- Not for now, by default we are running connections in persistent mode, which can cause issues with transactions.
- โ Update one of the project currently using StaticPHP to get the idea of whether we are not missing any required variable to be available globally in view files.
- โ Choose documentation parser.
- โ Check whether form validation helper still works and how it applies to Twig.
- Works now and can be registered with twig by running \models\fv::twig_register();
- โ Pages helper should register it self with Twig once loadded and if Twig is available.
- Nop, pagination html can be passed in the view as variable.
- โ Change all include to require, so that we don't expose StaticPHP to any security issues by doing something that can't be done.
- โ Update StaticPHP start page.
- โ Add filesystem helpers to core \load class.
- โ Logger interface through core\load class.
- โ Go through core router class and make sure there are no redundant methods.
- โ Rename all class methods in camelCase format to comply with php-fip standards. Also possibly filenames.
- โ Check whether url prefixes are working.
- โ Check before_controller hook.