Updated api/2.2 notice and minupd for main README

This commit is contained in:
xdrm-brackets 2017-09-07 20:17:30 +02:00
parent 7467b15664
commit 2a74ae51e7
2 changed files with 23 additions and 13 deletions

View File

@ -10,9 +10,9 @@ xdrm-framework is a tool that wraps my framework and all it's component's versio
To use the xdrm-framework's project builder, just open a linux terminal and type : To use the xdrm-framework's project builder, just open a linux terminal and type :
1. `./xfw packages` - to display the available modules 1. `./xfw packages` - to display the available modules
2. `./xfw install {packageName}:1.2` - to install a package and its version (1.2 here) 2. `./xfw install @pkg_name:1.2` - to install a package and its version (1.2 here)
3. `./xfw remove {packageName}` - to disable a module 3. `./xfw remove @pkg_name` - to disable a module
4. `./xfw build {projectRoot}` - will create your project in the folder `{projectRoot}` 4. `./xfw build @project_root` - will create your project in the folder `@project_root`
5. `./xfw init` - to remove all enabled modules 5. `./xfw init` - to remove all enabled modules
#### 2. Project's file structure #### 2. Project's file structure

View File

@ -66,13 +66,13 @@ The API is based over a 2-level delegation structure :
So each of your functionalities must have a `method` name and be inside a `module`. So each of your functionalities must have a `method` name and be inside a `module`.
<u>Example:</u> <u>Example:</u>
* module `article` contains methods: * the module `article` contains methods:
* `read` with argument `article_id` * `read` with argument `article_id` (to identify the wanted article)
* `write` with arguments `title` and `body` * `write` with arguments `title` and `body` (data to write into the new created article)
* `edit` with arguments `article_id` and `body` * `edit` with arguments `article_id` and `body` (to identify and replace the body)
* `delete` with argument `article_id` * `delete` with argument `article_id` (to identify which article to delete)
If you want to delete the article of id `52`, I must request `article/delete` passing `article_id`=`52`. If you want to delete the article of id `52`, you must request `article/delete` passing `article_id`=`52`.
2 - Usage 2 - Usage
---- ----
@ -160,8 +160,8 @@ In order to setup an automatic bound from HTTP requests to API directly, you mus
```php ```php
// let's suppose the url is `/api/{module}/{method}` // let's suppose the url is `/api/{module}/{method}`
$url = '/api/somemodule/somemethod/1/2/'; $url = '/api/somemodule/somemethod/1/2/';
$url = substr($url, strlen('/api')); $uri = substr($url, strlen('/api'));
// $url = /somemodule/somemethod/1/2/ // $uri = /somemodule/somemethod/1/2/
``` ```
> ### 2) give the url to the HTTP manager > ### 2) give the url to the HTTP manager
@ -248,13 +248,15 @@ Then can handle various kinds of URL :
|`{method_description}`|textual description|"Returns a specific article"| |`{method_description}`|textual description|"Returns a specific article"|
|`{method_perm}`|permission array|`["poster", "admin", "user"]`| |`{method_perm}`|permission array|`["poster", "admin", "user"]`|
|`{is_downloadable}`|If you want this method to return a file|`true`, `false`| |`{is_downloadable}`|If you want this method to return a file|`true`, `false`|
|`{name_param}`|Your param's name|"id_article"| |`{name_param}`|Your param's name _*_|"id_article"|
|`{desc_param}`|Your param's description|"Wanted article's id"| |`{desc_param}`|Your param's description|"Wanted article's id"|
|`{type_param}`|Your param's type (cf. Checker)|"Wanted article's type"| |`{type_param}`|Your param's type (cf. Checker)|"Wanted article's type"|
|`{is_optional}`|Whether to make your param _required_|`true`, `false`| |`{is_optional}`|Whether to make your param _required_|`true`, `false`|
|`{name_output}`|Your output's name|"article"| |`{name_output}`|Your output's name|"article"|
|`{desc_output}`|Your output's description|"Article content"| |`{desc_output}`|Your output's description|"Article content"|
_*_ If you want URL (GET) parameters, the {param_name} must be `URL_0`, `URL_1` and so on according to the index wanted in the URL.
> `api/module/method/URL_0/URL_1/URL_2/`
4 - implementation 4 - implementation
---- ----
@ -284,10 +286,11 @@ Arguments are passed to the method as a single argument which an associative arr
_Notes_: _Notes_:
* Optional parameters if not given are set to `null` * Optional parameters if not given are set to `null`
* parameters of type `FILE` are given by reference but the use is the same as normal parameters * parameters of type `FILE` are given by reference but the use is the same as normal parameters
* URL parameters are called `URL_0`, `URL_1` and so on according to their order.
### Ouput required ### Ouput required
You must return an associative array containing at least the field `error` containing an instance of `/api/core/Error`, then you can add useful return. You must return an associative array containing at least the field `error` containing an instance of `/api/core/Error`, then you can add whatever you want to return in the array.
If you don't return the 'error' field, by default it is set to `new Error(Err::Success)`. If you don't return the 'error' field, by default it is set to `new Error(Err::Success)`.
@ -327,3 +330,10 @@ To add a new type, just open the file `/build/api/Checker.php` and add an entry
> **Note:** It is possible to chain `array` type as many as needed. > **Note:** It is possible to chain `array` type as many as needed.
**Ex.:** `array<array<id>>` - Will match array only containing arrays that only contains `id` entries. **Ex.:** `array<array<id>>` - Will match array only containing arrays that only contains `id` entries.
## (5) Advanced
### Before and After scripts
Each time a **method** is called, the api **creates an instance** from the class, and after the execution, the class is **destroyed**. So you can implement the methods `__construct` and `__destruct` to add before and after scripts.