3.5 KiB
xdrm-framework
Description
xdrm-framework is a tool that wraps my framework and all it's component's versions. It allows to build a web framework's base with chosen modules and their versions.
1. Build a project
To use the xdrm-framework's project builder, just open a linux terminal and type :
xdrm-framework modules
- to display the available modulesxdrm-framework install {moduleName} 1.2
- to enable a module and its version (1.2 here)xdrm-framework remove {moduleName}
- to disable a modulexdrm-framework build {projectRoot}
- will create your project in the folder{projectRoot}
xdrm-framework init
- to remove all enabled modules
2. Project's file structure
xdrm-framework is based on all is in config
so you will have this structure :
- folder
build
which contains framework's modules (core + data). - folder
public_html
which contains visible content (html, css, js). - folder
config
which contains the modules' config files (mainly json). - file
autoloader.php
which will auto-load the components.
Note: In every php file you want to use framework's classes, you have to begin your file by :
<?php
/* [1] load the autoloader with correct path */
require_once '../autoloader.php';
/* [2] then you can load your classes */
use api\core\Request; // ex1: api request manager
use error\core\Error; // ex2: error manager
use error\core\Err; // ex3: error codes
/* [3] and use them as long as you want without namespace */
$request = new Request('module/method', ['id_user' => 10]);
$response = $request->dispatch();
if( $response->error->get() === Err::Success )
echo "All is going right!\n";
Note: Some global constants are created into the autoloader so they are accessible from any file which loads the autoloader:
__BUILD__
- The absolutebuild
folder path__PUBLIC__
- The absolutepublic_html
folder path__ROOT__
- The absoluteroot
path (project root)__CONFIG__
- The absoluteconfig
folder path
3. Modules
[3.1] API - self-managed API
How to use
In order to use the API, you must begin by writting your "methods" in the configuration file located at /config/modules.json
.
In order to be understood, lets call module
a group of methods, and method
a function which outputs data from input parameters.
Configuration format
{
"{module_name}": {
"{http_method}::{method_name}": {
"description": "{method_description}",
"permissions": ["{perm}"],
"options": { "download": {is_download} },
"parameters: {
"{name_param}": { "description": "{desc_param}", "type": "{type_param}", "optional": {is_optional} }
},
"output": {
"{name_output}": { "description": "{desc_output}", "type": "{type_output}" }
}
}
}
}
Classes (advanced)
The API is managed through 5 classes :
- Request - is the core of the module
- Response - renders and manages the responses
- Authentification - manages the authentification part (it has to be over written for each case)
- Checker - manages auto checked parameters' types
- ModuleFactory - to instanciate each module, transparent to the user