update api:2.2 notice -> now Request+Response class doc done
This commit is contained in:
parent
7dda3504f1
commit
9bd6212f5f
|
@ -52,8 +52,8 @@ The aim of this package is to make your life easier working with APIs or interna
|
||||||
|
|
||||||
Things you have to do :
|
Things you have to do :
|
||||||
- implement your processes (obviously)
|
- implement your processes (obviously)
|
||||||
- implement your authentication system (cf. [AuthSystem](#3-authsysten))
|
- implement your authentication system (cf. [AuthSystem](#1-permissions--authsystem))
|
||||||
- edit the configuration file (cf. [configuration](#3---configuration))
|
- edit the configuration file (cf. [configuration](#iii-configuration))
|
||||||
|
|
||||||
Things you **don't have** to do :
|
Things you **don't have** to do :
|
||||||
- input type check (cf. [Checker](#4-checker))
|
- input type check (cf. [Checker](#4-checker))
|
||||||
|
@ -92,8 +92,8 @@ If you want to delete the article of id `52`, you must request `article/delete`
|
||||||
> ## **1** Setup
|
> ## **1** Setup
|
||||||
|
|
||||||
In order to make the API work, you have to :
|
In order to make the API work, you have to :
|
||||||
1. Edit the configuration file according to your needs (cf. [configuration](#3---configuration))
|
1. Edit the configuration file according to your needs (cf. [configuration](#iii-configuration))
|
||||||
2. Implement the Authentication System to manage permissions (cf. [AuthSystem](#3-authsystem))
|
2. Implement the Authentication System to manage permissions (cf. [AuthSystem](#1-permissions--authsystem))
|
||||||
3. Implement the code of the methods according to the configuration
|
3. Implement the code of the methods according to the configuration
|
||||||
|
|
||||||
|
|
||||||
|
@ -321,6 +321,97 @@ If you don't return the 'error' field, by default it is set to `new Error(Err::S
|
||||||
|
|
||||||
> # **V.** Class documentation
|
> # **V.** Class documentation
|
||||||
|
|
||||||
|
> ## **1** Request
|
||||||
|
|
||||||
|
### Attributes
|
||||||
|
|
||||||
|
The attribute `error` will contain the current `Error` instance.
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
public $error;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Methods
|
||||||
|
|
||||||
|
Creates a new `Request` object, you must give it a path following the pattern "module/method", the params must be an associative array. Note that the path can be inside the `$params` variable.
|
||||||
|
|
||||||
|
It checks missing params and each needed params' type according to the **Checker** implementation (cf. [Checker](#4-checker)). It also checks the permissions you have according to the **AuthSystem** implementation (cf. [AuthSystem](#1-permissions--authsystem)).
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
public function __construct(String $path, Array $params) : Request;
|
||||||
|
```
|
||||||
|
|
||||||
|
Creates a new `Request` object but from the URL. It will seek for the *path* in the URL, then in the data. (it will call itself the **\_\_construct()** method).
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
public static function remote(String $url, Array $data) : Request;
|
||||||
|
```
|
||||||
|
|
||||||
|
Registers the **AuthSystem** you want, must be done before any construction.
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
public static function setAuthSystem(Request $instance) : bool;
|
||||||
|
```
|
||||||
|
|
||||||
|
Executes the current `Request` object and returns a `Response` object.
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
public function dispatch() : Response;
|
||||||
|
```
|
||||||
|
|
||||||
|
Same as `dispatch()` but manages the **download** option (cf. [Configuration](#iii-configuration)). It will use 2 of the parameters you must return on success : `body`, and `headers`. The first one must contain the content of the file to create, the second the headers in an associative array.
|
||||||
|
|
||||||
|
The call will become the file itself.
|
||||||
|
|
||||||
|
Note: If the `HTTP_X_REQUESTED_WITH` header is present, it will create the downloadable file as **/tmp/download_{some\_hash}** and return a normal `Response` object with the field `link` containing the file absolute path.
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
public function download() : null;
|
||||||
|
public function download() : Response; // if called by Ajax
|
||||||
|
```
|
||||||
|
|
||||||
|
> ## **2** Response
|
||||||
|
|
||||||
|
### Attributes
|
||||||
|
|
||||||
|
The attribute `error` will contain the current `Error` instance.
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
public $error;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Methods
|
||||||
|
|
||||||
|
Returns an associative array containing the whole response data (excluding the error).
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
public function getAll() : Array;
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns only the field from the response data (if it exists).
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
public function get(String $key) : mixed; // on success
|
||||||
|
public function get(String $key) : null; // on error
|
||||||
|
```
|
||||||
|
|
||||||
|
Sets the `HTTP_CODE` according to the `Error` argument, also it sets the header for **application/json**.
|
||||||
|
|
||||||
|
It can be used for simple API response, it will add the *"error"* and *"ErrorDescription"* fields to the data and set the headers so you can display the result of the API call.
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
public function serialize() : String;
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
> ## **4** Checker
|
> ## **4** Checker
|
||||||
|
|
||||||
`Checker` checks the input values according to the type given in the configuration.
|
`Checker` checks the input values according to the type given in the configuration.
|
||||||
|
|
Loading…
Reference in New Issue