A PHP framework for easy creation of high-performance, multi-lingual websites.
This framework does not contain pre-defined HTML code or something like that, the purpose of it is to organize your code and eliminate code duplication while providing maximum performance.
In the following is described how to build a website with this framework:
The config file gets included before the execution of any PHP file inside the views directory.
The idea is to define your custom constants/variables inside of it.
However credentials should be placed in the .env file for security reasons.
The global constants can already be used inside of the config.php however the TEXT constant won't be available at this point!
This file handles all requests and is the heart of this framework. At the top of it you have some customization options, however the framework comes fully functioning out of the box so it is not necessary to change something in it in order to use the framework.
Inside of the views folder you put your PHP or HTML files that define the layout for each page view of your website.
The structure inside the views folder is important because it also defines how the URLs, that the user calls, will look like later on.
For example if you place a file the following views/login/index.php then the resulting URL to request the file
will be https://<yourDomain>/<languageCode>/login/.
If the static directory contains an equal path as inside views, the path inside static is preferred, however if the
file does not exist in static then the path inside views will be looked up. This allows to have e.g. the directory static/downloads/ in which
files for download are put and at the same time a directory views/downloads/ which defines the view.
The translations directory contains JSON files that contain the actual text in a specific language.
Inside the translations/globals.json you can define text variables that should be available in every language
e.g. all the native language names.
Important is that the name of the JSON files should be the language code the file represents e.g. en.json, zh-Hans.json, etc.
Inside the text you can use PHP constants defined by this framework or in the config.php file by simply enclosing them in %% e.g.
"Some text with a %%MY_CONSTANT%%". Variables cannot be referenced inside translations for security reasons.
Longer texts like legal notices can be put into separate files inside the translations directory and the file content can be included
using the following <?php include(TRANSLATIONS.<pathInsideTranslationsDir>); ?>
You can put CSS files into the css-components directory, however they can not directly be called from an URL!
Instead you can define in css-components/css-config.php CSS file names that should be generated as keys
and as values an array of CSS file names you've created inside css-components. Calling a file name defined as key will
automatically generate the appropriate file inside static/css/ consisting of the contents of the file names defined in the value array.
The static/css/ folder in which the generated files are placed is publicly available under https://<yourDomain>/css/.
If a file inside the css-components folder has changed the generated files inside the static/css/ folder will be automatically updated.
You can put JavaScript files into the js-components directory, however they can not directly be called from an URL!
Instead you can define in js-components/js-config.php JavaScript file names that should be generated as keys
and as values an array of JavaScript file names you've created inside js-components. Calling a file name defined as key will
automatically generate the appropriate file inside static/js/ consisting of the contents of the file names defined in the value array.
The static/js/ folder in which the generated files are placed is publicly available under https://<yourDomain>/js/.
If a file inside the js-components folder has changed the generated files inside the js folder will be automatically updated.
Inside the scripts directory you can put PHP scripts that you can call from the views files either with
include(SCRIPTS.'<fileInsideScriptsDir>'); or with require_once(SCRIPTS.'<fileInsideScriptsDir>');.
It also makes sense to put recurring parts of the views files like header and footer in there e.g. scripts/header.php
and then inside a view file e.g. views/start/index.php you can include it with include(SCRIPTS.'header.php');.
Script that can be included and defines some functions to easily set HTTP headers for caching. It is also used by the framework to set caching headers for CSS, JavaScript, images and downloads.
Script defines functions for working with JWT tokens as well as some functions for a JWT session
instead of the default session_start() function. The advantage of a JWT session is that
it does store all information in the cookie and is therefore not dependend on the local storage of
the server like the default PHP session (needed if multiple server instances are used).
If script is not wanted it can be safely deleted as it is not used by the actual framework.
Important: First generate a random, long secret key and put it in the .env file for the variable JWT_SECRET_KEY!
Example how to use the JWT session, further documentation inside the script file:
require_once(SCRIPTS.'jwt-session.php'); // include script
$jsonObj = jwt_session_load(); // Load session from cookie
// Read/Write session
$jsonObj->name = "foo";
$jsonObj->admin = true;
jwt_session_store($jsonObj); // Store session in cookie (must be done before any HTML gets sent)Everything inside the static directory is directly publicly accessible without the word static in the URL e.g.
static/css/start.css --> https://<yourDomain>/css/start.css.
Every direct subdirectory of the static directory e.g. static/images/ gets a constant with the same name in uppercase defined e.g. IMAGES
with a relative path the named subdirectory such that the constant can be used as prefix in links e.g. <img src="<?php echo IMAGES; ?>favicons/favicon.ico">.
If you use an equal path inside the static directory as in the views diretory have a look at views/ for details.
Files automatically generated out of the css-components will be placed here.
However you can also directly place static CSS files inside of this folder.
All files of the static/css/ folder are publicly accessible over the URL https://<yourDomain>/css/.
Files automatically generated out of the js-components will be placed here.
However you can also directly place static JavaScript files inside of this folder.
All files of the static/js/ folder are publicly accessible over the URL https://<yourDomain>/js/.
The idea of the images folder is that it contains all the images, however it is not required and can be deleted if wanted.
Referencing images inside your code looks like the following <?php echo IMAGES.'<pathInsideImagesDir>'; ?>
where the constant IMAGES will get replaced with the relative path to the images/ directory. So you need just to
append your path as if you were inside the images/ directory.
For example <?php echo IMAGES.'favicons/favicon.ico'; ?>
The sitemap.php file automatically generates and updates a sitemap.xml file.
Simply define the individual URLs of your website at the top of the sitemap.php.
Language code prefixes will be automatically added to the URLs.
Contains environment variables that get loaded for every request and can be accessed either by referecing with $_ENV
or by calling getenv().
Secrets that should never be exposed must be defined as environment variables such as credentials for database for example.
The .htaccess files tells the apache server that all HTTP requests inside of this repository should be handled by the index.php file.
CSSRelative path to the CSS directorystatic/css/that can be used for linksJSRelative path to the JavaScript directorystatic/js/that can be used for links- For each subdirectory of
static/an equaly named constant with an relative path to the subdirectory gets created e.g.static/images/-->IMAGESthat can be used for links SCRIPTSPath to the internalscripts/directory, can only be used withinclude()orrequire_once()TEXTArray loaded with the translation variables from thetranslations/globals.jsonand the language specific translation file insidetranslations/LANGUAGE_CODELanguage code of the language in which the page should be displayed e.g.enfor English,defor German, etcFULL_REQUESTRequested URI with the language prefix in front of it if given e.g.en/users/login/index.phporcss/start.cssREQUESTRequested URI without the language prefix in front of it e.g.users/login/index.phporcss/start.cssREQUEST_PREFIXTypically same asREQUESTexcept if match in thePREFIX_FALLBACKSarray is found, then its equal to the matched prefixREQUEST_SUFFIXTypicallyfalseexcept if match in thePREFIX_FALLBACKSarray is found, then value is the part of the requested URI that comes after the prefixREQUEST_SUFFIX_PARTSArray that contains the parts ofREQUEST_SUFFIXseperated by/or emptyREQUEST_PREFIX_BASERelative path to the prefix part of the URI that can be used in links etc (zero or multiple../)BASERelative path to the language specific root that can be used to send user back to root URL without droping the language prefixROOTRelative path to absolute root which means that also the language prefix will be droppedBASE_DEPTHInteger how deep the requested file is without the language prefix taken into account e.g.en/users/login/index.php-->2ROOT_DEPTHInteger how deep the requested file is including the language prefix e.g.en/users/login/index.php-->3SUPPORTED_LANGUAGESArray with language codes that were found in thetranslations/directory$_ENVSimilar to$_GETbut instead to retrieve to environment variables defined in the.envfilePROJECT_ROOTPath from the document root of the web server$_SERVER['DOCUMENT_ROOT']to the root of the project (just '/' if project/framework is directly in document root and not in a subdirectory). Used in scripts/metatags.php for alternate URLs
The framework also comes with some example files that can be deleted if wanted:
css-components/default.cssandcss-components/start.cssare example CSS component files for the example start pagejs-components/default.jsandjs-components/start.jsare example JavaScript component files for the example start pagescripts/metatags.phpScript containing generic HTML metatags that should be included in every pagestatic/css/start.cssExample CSS file that was generated by the start page as defined incss-components/css-config.phpstatic/images/faviconsIdea is to place the favicon in different formats and resolutions for different browser in herestatic/js/start.jsExample JavaScript file that was generated by the start page as defined injs-components/js-config.phptranslations/en.jsonandtranslations/de.jsonare two example translation filesviews/error/Contains index file that shows an example error pageviews/language-editor/primitive editor to easily edit the translation files, however it is not secure and should not be deployed!views/start/Contains index file that shows an example start pageviews/browserconfig.xmlFile used by browsers to get metadata about the websiteviews/index.phpRedirects to the example start pageviews/manifest.jsonFile used by browsers to get metadata about the websiteviews/robots.txtInside of this file you can declare URLs that should not be crawled and indexed by search engines
For deployment in production mode following points should be checked:
- The environmental variable
DEVmust not be present or at least set tofalse. Check file.env. - Proper caching should be set in every PHP file inside the view directory (you can use
scripts/caching.php). - In
sitemap.phpall important URIs should be defined. - In the root
index.phpcheck following settings:HTTPS_REDIRECTshould be set totrue.STATICS_CACHE_SECONDSshould have proper caching values set.