{"id":20345980,"url":"https://github.com/lupcode/php-framework","last_synced_at":"2025-10-25T12:22:57.509Z","repository":{"id":48422031,"uuid":"388235314","full_name":"LupCode/php-framework","owner":"LupCode","description":"A PHP framework for easy and efficient creation of multi-lingual websites","archived":false,"fork":false,"pushed_at":"2024-11-04T21:48:35.000Z","size":173,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-14T21:48:03.126Z","etag":null,"topics":["dynamic-css","dynamic-html","dynamic-javascript","dynamic-js","framework","i18n","jwt","jwt-tokens","l10n","multi-language","multi-lingual","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LupCode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-21T20:15:39.000Z","updated_at":"2024-11-04T21:47:12.000Z","dependencies_parsed_at":"2025-01-14T21:36:37.862Z","dependency_job_id":"f622faf2-ac2b-4071-bdd0-f54bb7eca513","html_url":"https://github.com/LupCode/php-framework","commit_stats":null,"previous_names":[],"tags_count":4,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LupCode%2Fphp-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LupCode%2Fphp-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LupCode%2Fphp-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LupCode%2Fphp-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LupCode","download_url":"https://codeload.github.com/LupCode/php-framework/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241876760,"owners_count":20035400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dynamic-css","dynamic-html","dynamic-javascript","dynamic-js","framework","i18n","jwt","jwt-tokens","l10n","multi-language","multi-lingual","php"],"created_at":"2024-11-14T22:10:38.609Z","updated_at":"2025-10-25T12:22:57.414Z","avatar_url":"https://github.com/LupCode.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Framework\r\nA PHP framework for easy creation of high-performance, multi-lingual websites.  \r\n\r\nThis framework does not contain pre-defined HTML code or something like that, \r\nthe purpose of it is to organize your code and eliminate code duplication while \r\nproviding maximum performance. \r\n\r\n## How to use\r\nIn the following is described how to build a website with this framework:\r\n\r\n### Structure\r\n#### `config.php`\r\nThe config file gets included before the execution of any PHP file inside the `views` directory. \r\nThe idea is to define your custom constants/variables inside of it. \r\nHowever credentials should be placed in the `.env` file for security reasons.\r\nThe global constants can already be used inside of the `config.php` however the `TEXT` constant won't be available at this point!\r\n\r\n#### `index.php`\r\nThis file handles all requests and is the heart of this framework. \r\nAt 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 \r\nsomething in it in order to use the framework.  \r\n\r\n#### `views/`\r\nInside of the `views` folder you put your PHP or HTML files that define the layout for each page view of your website. \r\nThe structure inside the `views` folder is important because it also defines how the URLs, that the user calls, will look like later on.  \r\nFor example if you place a file the following `views/login/index.php` then the resulting URL to request the file \r\nwill be  `https://\u003cyourDomain\u003e/\u003clanguageCode\u003e/login/`.  \r\nIf the `static` directory contains an equal path as inside `views`, the path inside `static` is preferred, however if the \r\nfile 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 \r\nfiles for download are put and at the same time a directory `views/downloads/` which defines the view.\r\n\r\n#### `translations/`\r\nThe `translations` directory contains JSON files that contain the actual text in a specific language.  \r\nInside the `translations/globals.json` you can define text variables that should be available in every language  \r\ne.g. all the native language names.  \r\nImportant is that the name of the JSON files should be the language code the file represents e.g. `en.json`, `zh-Hans.json`, etc.  \r\nInside the text you can use PHP constants defined by this framework or in the `config.php` file by simply enclosing them in `%%` e.g. \r\n`\"Some text with a %%MY_CONSTANT%%\"`. Variables cannot be referenced inside translations for security reasons.  \r\nLonger texts like legal notices can be put into separate files inside the `translations` directory and the file content can be included \r\nusing the following `\u003c?php include(TRANSLATIONS.\u003cpathInsideTranslationsDir\u003e); ?\u003e`\r\n\r\n#### `css-components/`\r\nYou can put CSS files into the `css-components` directory, however they can not directly be called from an URL!  \r\nInstead you can define in `css-components/css-config.php` CSS file names that should be generated as keys \r\nand as values an array of CSS file names you've created inside `css-components`. Calling a file name defined as key will \r\nautomatically generate the appropriate file inside `static/css/` consisting of the contents of the file names defined in the value array. \r\nThe `static/css/` folder in which the generated files are placed is publicly available under `https://\u003cyourDomain\u003e/css/`. \r\nIf a file inside the `css-components` folder has changed the generated files inside the `static/css/` folder will be automatically updated. \r\n\r\n#### `js-components/`\r\nYou can put JavaScript files into the `js-components` directory, however they can not directly be called from an URL!  \r\nInstead you can define in `js-components/js-config.php` JavaScript file names that should be generated as keys \r\nand as values an array of JavaScript file names you've created inside `js-components`. Calling a file name defined as key will \r\nautomatically generate the appropriate file inside `static/js/` consisting of the contents of the file names defined in the value array. \r\nThe `static/js/` folder in which the generated files are placed is publicly available under `https://\u003cyourDomain\u003e/js/`. \r\nIf a file inside the `js-components` folder has changed the generated files inside the `js` folder will be automatically updated. \r\n\r\n#### `scripts/`\r\nInside the `scripts` directory you can put PHP scripts that you can call from the views files either with \r\n`include(SCRIPTS.'\u003cfileInsideScriptsDir\u003e');` or with `require_once(SCRIPTS.'\u003cfileInsideScriptsDir\u003e');`.  \r\nIt also makes sense to put recurring parts of the views files like header and footer in there e.g. `scripts/header.php` \r\nand then inside a view file e.g. `views/start/index.php` you can include it with `include(SCRIPTS.'header.php');`. \r\n\r\n#### `scripts/caching.php` \r\nScript that can be included and defines some functions to easily set HTTP headers for caching. \r\nIt is also used by the framework to set caching headers for CSS, JavaScript, images and downloads.\r\n\r\n#### `scripts/jwt-session.php`\r\nScript defines functions for working with JWT tokens as well as some functions for a JWT session \r\ninstead of the default `session_start()` function. The advantage of a JWT session is that \r\nit does store all information in the cookie and is therefore not dependend on the local storage of \r\nthe server like the default PHP session (needed if multiple server instances are used). \r\nIf script is not wanted it can be safely deleted as it is not used by the actual framework.  \r\n**Important:** First generate a random, long secret key and put it in the `.env` file for the variable `JWT_SECRET_KEY`!\r\nExample how to use the JWT session, further documentation inside the script file: \r\n```php\r\nrequire_once(SCRIPTS.'jwt-session.php'); // include script\r\n$jsonObj = jwt_session_load(); // Load session from cookie\r\n\r\n// Read/Write session\r\n$jsonObj-\u003ename = \"foo\";\r\n$jsonObj-\u003eadmin = true;\r\n\r\njwt_session_store($jsonObj); // Store session in cookie (must be done before any HTML gets sent)\r\n```\r\n\r\n#### `static/`\r\nEverything inside the `static` directory is directly publicly accessible without the word `static` in the URL e.g. \r\n`static/css/start.css` --\u003e `https://\u003cyourDomain\u003e/css/start.css`.  \r\nEvery direct subdirectory of the `static` directory e.g. `static/images/` gets a constant with the same name in uppercase defined e.g. `IMAGES` \r\nwith a relative path the named subdirectory such that the constant can be used as prefix in links e.g. `\u003cimg src=\"\u003c?php echo IMAGES; ?\u003efavicons/favicon.ico\"\u003e`.  \r\nIf you use an equal path inside the `static` directory as in the `views` diretory have a look at [views/](#views) for details. \r\n\r\n#### `static/css/`\r\nFiles automatically generated out of the `css-components` will be placed here. \r\nHowever you can also directly place static CSS files inside of this folder. \r\nAll files of the `static/css/` folder are publicly accessible over the URL `https://\u003cyourDomain\u003e/css/`.\r\n\r\n#### `static/js/`\r\nFiles automatically generated out of the `js-components` will be placed here. \r\nHowever you can also directly place static JavaScript files inside of this folder. \r\nAll files of the `static/js/` folder are publicly accessible over the URL `https://\u003cyourDomain\u003e/js/`.\r\n\r\n#### `static/images/`\r\nThe idea of the `images` folder is that it contains all the images, however it is not required and can be deleted if wanted. \r\nReferencing images inside your code looks like the following `\u003c?php echo IMAGES.'\u003cpathInsideImagesDir\u003e'; ?\u003e` \r\nwhere the constant `IMAGES` will get replaced with the relative path to the `images/` directory. So you need just to \r\nappend your path as if you were inside the `images/` directory.\r\nFor  example `\u003c?php echo IMAGES.'favicons/favicon.ico'; ?\u003e`\r\n\r\n#### `sitemap.php`\r\nThe `sitemap.php` file automatically generates and updates a `sitemap.xml` file. \r\nSimply define the individual URLs of your website at the top of the `sitemap.php`. \r\nLanguage code prefixes will be automatically added to the URLs.\r\n\r\n#### `.env`\r\nContains environment variables that get loaded for every request and can be accessed either by referecing with `$_ENV`\r\nor by calling `getenv()`. \r\nSecrets that should never be exposed must be defined as environment variables such as credentials for database for example.\r\n\r\n#### `.htaccess`\r\nThe `.htaccess` files tells the apache server that all HTTP requests inside of this repository should be handled by the `index.php` file.\r\n\r\n### Global Constants\r\n* `CSS` Relative path to the CSS directory `static/css/` that can be used for links\r\n* `JS` Relative path to the JavaScript directory `static/js/` that can be used for links\r\n* For each subdirectory of `static/` an equaly named constant with an relative path to the subdirectory gets created e.g. `static/images/` --\u003e `IMAGES` \r\nthat can be used for links\r\n* `SCRIPTS` Path to the internal `scripts/` directory, can only be used with `include()` or `require_once()`\r\n* `TEXT` Array loaded with the translation variables from the `translations/globals.json` and the language specific translation file inside `translations/`\r\n* `LANGUAGE_CODE` Language code of the language in which the page should be displayed e.g. `en` for English, `de` for German, etc\r\n* `FULL_REQUEST` Requested URI with the language prefix in front of it if given e.g. `en/users/login/index.php` or `css/start.css`\r\n* `REQUEST` Requested URI without the language prefix in front of it e.g. `users/login/index.php` or `css/start.css`\r\n* `REQUEST_PREFIX` Typically same as `REQUEST` except if match in the `PREFIX_FALLBACKS` array is found, then its equal to the matched prefix\r\n* `REQUEST_SUFFIX` Typically `false` except if match in the `PREFIX_FALLBACKS` array is found, then value is the part of the requested URI that comes after the prefix\r\n* `REQUEST_SUFFIX_PARTS` Array that contains the parts of `REQUEST_SUFFIX` seperated by `/` or empty\r\n* `REQUEST_PREFIX_BASE` Relative path to the prefix part of the URI that can be used in links etc (zero or multiple `../`)\r\n* `BASE` Relative path to the language specific root that can be used to send user back to root URL without droping the language prefix\r\n* `ROOT` Relative path to absolute root which means that also the language prefix will be dropped\r\n* `BASE_DEPTH` Integer how deep the requested file is without the language prefix taken into account e.g. `en/users/login/index.php` --\u003e `2`\r\n* `ROOT_DEPTH` Integer how deep the requested file is including the language prefix e.g. `en/users/login/index.php` --\u003e `3`\r\n* `SUPPORTED_LANGUAGES` Array with language codes that were found in the `translations/` directory\r\n* `$_ENV` Similar to `$_GET` but instead to retrieve to environment variables defined in the `.env` file\r\n* `PROJECT_ROOT` Path 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\r\n\r\n### Example files that can be deleted\r\nThe framework also comes with some example files that can be deleted if wanted:\r\n* `css-components/default.css` and `css-components/start.css` are example CSS component files for the example start page\r\n* `js-components/default.js` and `js-components/start.js` are example JavaScript component files for the example start page\r\n* `scripts/metatags.php` Script containing generic HTML metatags that should be included in every page\r\n* `static/css/start.css` Example CSS file that was generated by the start page as defined in `css-components/css-config.php`\r\n* `static/images/favicons` Idea is to place the favicon in different formats and resolutions for different browser in here\r\n* `static/js/start.js` Example JavaScript file that was generated by the start page as defined in `js-components/js-config.php`\r\n* `translations/en.json` and `translations/de.json` are two example translation files\r\n* `views/error/` Contains index file that shows an example error page\r\n* `views/language-editor/` primitive editor to easily edit the translation files, however it is **not secure** and should not be deployed!\r\n* `views/start/` Contains index file that shows an example start page\r\n* `views/browserconfig.xml` File used by browsers to get metadata about the website\r\n* `views/index.php` Redirects to the example start page\r\n* `views/manifest.json` File used by browsers to get metadata about the website\r\n* `views/robots.txt` Inside of this file you can declare URLs that should not be crawled and indexed by search engines\r\n\r\n\r\n## How to deploy\r\nFor deployment in production mode following points should be checked:\r\n* The environmental variable `DEV` must not be present or at least set to `false`. Check file `.env`.\r\n* Proper caching should be set in every PHP file inside the view directory (you can use `scripts/caching.php`).\r\n* In `sitemap.php` all important URIs should be defined.\r\n* In the root `index.php` check following settings:\r\n  * `HTTPS_REDIRECT` should be set to `true`.\r\n  * `STATICS_CACHE_SECONDS` should have proper caching values set.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flupcode%2Fphp-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flupcode%2Fphp-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flupcode%2Fphp-framework/lists"}