- Implement default list and retrieve serializers for CRUD Controller
- Implement
- pagination,
- filters,
- and sorting for default list controller
- Run
git clone {path} && cd {repo_name} - Create database
- Pass sensitive data with env variable or create loc.{config_file_name} and rewrite variables
- Make migrations
php Manage.php -c migrate - Redirect all requests to index.php by frontend web server(Apache, nginx, php-fpm etc.)
- Open
/api/v1/pingto check if app was successfully installed
- PHP 7.2+
There are three main components from which backend server is composed.
- Model - implements interaction with db and some encapsulated model functionality
- Module - implements interactions and compositions of several models
- Serializer - serializes/wraps output of model or module
- And Controller which just calls Model or Module and wraps output in a Serializer. It is like a combine which calls components in a right order and returns result.
To avoid "Spaghetti" code follow this mini-guide
- 0 means Column-component can not be imported* in Raw-component
- 1 means Column-component can be imported* in Raw-component
| # | Model | Module | Serializer | Controller |
|---|---|---|---|---|
| Model | 0 | 1 | 0 | 1 |
| Module | 0 | 1 | 0 | 1 |
| Serializer | 0 | 0 | 1 | 1 |
| Controller | 0 | 0 | 0 | 0 |
- "imported" means an instance of type A can not be initialized in an instance of type B
| Request lifecycle | Procedure call | Example |
|---|---|---|
| 1. Matching route | - | - |
| 2. Parsing data | Engine\Parser | - |
| 3. Applying Middlewares | interface Core\Middleware | CORS, Localization, Auth, etc. |
| 4. Exec Controller | Callable | function/method |
| 5. Serializing(Wrapping) response | - | - |
| 6. Returning response | interface Core\Response | JsonResponse, HttpResponse |
- Model
- Each model should
- be extended from
Core\Db\Model - have
$table_name - implement function
fields()returning array of model fields
- be extended from
- Fields
- verifies values before writing to db
- available fields
CharFieldIntField - custom fields make sure that no invalid data will be written to the particular model, eg
IdFieldLoginFieldEmailField
- Special Fields
CreatedAtFieldUpdatedAtFieldDeletedAtField
- Autofilled Fields
RandomHashFieldRandomTokenField
- Each model should
- Routing
- Route:
Route::{method}('{path}', '{controller_namespace}@{controller}'); - Group:
Route::group('{preifx}', ...{Route|Route::group}); - Apply middleware
->middleware('{name}'); - Apply middleware on group
Route::groupMiddleware('{name}', array);
- Route:
- Controller
- Generics
ApiCRUDControllerBinds model default functionality to routes, supports 5 methods::read => GET /%n::list => GET::create => PUT::update => POST /%n::delete => DELETE /%n
$requestis passed to each controller- Get field value
$request['data']->get('{field}', array {filters});- Filters
required, default, int, double, positive, maxLen, minLen, oneOf, etc.
- Filters
- Get auth user
$request['user']
- Generics
- Command
- Entry point Manage.py
php Manage.php -c {command} migrateinitialises database and syncs migrations, supports--prefixmigrationcreates new file to write current database changes and stores it inMigrations\\dir, required argument--name, supports--prefixto store grouped migrations
- Entry point Manage.py
- Exceptions
- Each component has its exceptions inside its
Exceptiondir
- Each component has its exceptions inside its