Update `README.md`

Add/update commands + API description beginning.
This commit is contained in:
xdrm-brackets 2016-12-05 09:07:17 -05:00
parent 425363334c
commit 77afc40462
1 changed files with 53 additions and 14 deletions

View File

@ -9,36 +9,36 @@ To use the xdrm-framework's project builder, just open a linux terminal and type
1. `xdrm-framework modules` - to display the available modules 1. `xdrm-framework modules` - to display the available modules
2. `xdrm-framework enable {moduleName} 1.2` - to enable a module and its version (1.2 here) 2. `xdrm-framework enable {moduleName} 1.2` - to enable a module and its version (1.2 here)
3. `xdrm-framework disable {moduleName}` - to disable a module 3. `xdrm-framework disable {moduleName}` - to disable a module
4. `xdrm-framework build` - will create your project in the folder `built` 4. `xdrm-framework build {projectRoot}` - will create your project in the folder `{projectRoot}`
5. `mv built {yourPath}/{yourProjectName}` - to move your project wherever you want 5. `xdrm-framework init` - to remove all enabled modules
#### 2. Project's file structure #### 2. Project's file structure
xdrm-framework is based on `all is in config` so you will have this structure : xdrm-framework is based on `all is in config` so you will have this structure :
- folder `build` which contains framework's modules. - folder `build` which contains framework's modules (core + data).
- folder `public_html` which contains visible content. - folder `public_html` which contains visible content (html, css, js).
- folder `config` which contains the modules' config files. - folder `config` which contains the modules' config files (mainly json).
- file `autoloader.php` which will auto-load the components. - 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 : **Note:** In every php file you want to use framework's classes, you have to begin your file by :
```php ```php
<?php <?php
/* [1] dirname() as long as you're not at the project's root */ /* [1] load the autoloader with correct path */
define('__ROOT__', dirname(dirname(__FILE__))); require_once '../autoloader.php';
require_once __ROOT__.'/autoloader.php';
/* [2] then you can load your classes */ /* [2] then you can load your classes */
use api\core\ModuleRequest; use api\core\Request; // ex1: api request manager
use error\core\Error; 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 */ /* [3] and use them as long as you want without namespace */
$request = new ModuleRequest('module/method', ['id_user' => 10]); $request = new Request('module/method', ['id_user' => 10]);
$response = $request->dispatch(); $response = $request->dispatch();
if( $response->error === Error::Success ) if( $response->error->get() === Err::Success )
echo "All is going right!\n"; echo "All is going right!\n";
``` ```
**Note:** Some global constants are created into the autoloader: **Note:** Some global constants are created into the autoloader so they are accessible from any file which loads the autoloader:
- `__BUILD__` - The absolute `build` folder path - `__BUILD__` - The absolute `build` folder path
- `__PUBLIC__` - The absolute `public_html` folder path - `__PUBLIC__` - The absolute `public_html` folder path
- `__ROOT__` - The absolute `root` path (project root) - `__ROOT__` - The absolute `root` path (project root)
@ -47,7 +47,46 @@ xdrm-framework is based on `all is in config` so you will have this structure :
### 3. Modules ### 3. Modules
#### [3.1] api - self-managed API #### [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**
```json
{
"{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 :
1. Request - is the core of the module
2. Response - renders and manages the responses
3. Authentification - manages the authentification part (it has to be over written for each case)
4. Checker - manages auto checked parameters' types
5. ModuleFactory - to instanciate each module, transparent to the user
#### [3.2] error - error system #### [3.2] error - error system
#### [3.3] database - database wrapper and repository manager #### [3.3] database - database wrapper and repository manager
#### [3.4] orm - sql orm #### [3.4] orm - sql orm