skeleton: https://github.com/deweppro/framework-api-skeleton
<?php declare(strict_types=1);
require_once './../vendor/autoload.php';
Dewep\Config::setConfigPath(__DIR__.'/../config.yml');
(new Dewep\Application())->bootstrap();
To display in the response file in which the error occurred:
debug: true
The answer format for scalar answers is text/html; charset=utf-8
, for non - scalar answers::
response: application/json
You can add routes through the config file
routes:
/{user}/name:
GET,POST,PUT: Dewep\Demo::demo
/:
GET: Dewep\Demo::home
Where the placeholder {user}
will be passed to the controller as a variable:
public function demo(Request $request, string $user) {}
Or you can specify a route generator, which must contain a method - public function handler()
routes: \App\Routes
class Routes
{
public function handler()
{
$routes = [];
$routes['/{user}/name']['GET'] = 'Dewep\Demo::demo';
$routes['/{user}/name']['POST'] = 'Dewep\Demo::demo';
$routes['/{user}/name']['PUT'] = 'Dewep\Demo::demo';
$routes['/']['GET'] = 'Dewep\Demo::home';
return $routes;
}
}
You can specify the middleware to be executed before and after the main code is executed. Middleware should match the interface \Dewep\Interfaces\MiddlewareInterface
middleware:
before:
cookie: &CookieUserAuth
_: \Dewep\Middleware\Auth\Cookies
name: sess
secret: 'demo'
exp: 6000000
domain: localhost
after:
cookie: *CookieUserAuth
For dependency injection you can create providers that must match the interface Dewep\Interfaces\ProviderInterface
providers:
logger:
_: Dewep\Providers\LoggerProvider
debug: true
name: app
filename: app.log
mysql:
_: Dewep\Providers\MysqlProvider
host: localhost
port: 3306
dbname: default
login: default
password: default
Access to providers occurs through the Container: Container::get('logger')->...
Work with the console occurs through the console application
#!/usr/bin/env php
<?php
include_once __DIR__.'/vendor/autoload.php';
\Dewep\Config::setConfigPath(__DIR__.'/config.yml');
(new Dewep\Console())->bootstrap();
The console command is added to the config file as follows: command name: class
console:
app.restore: \Dewep\Handlers\Consoles\CreateDirs
All command classes must match the interface \Dewep\Interfaces\ConsoleInterface
Executing a command with parameters:
./console app.restore --demo=hello
View a list of commands:
./console
Commands list:
app.restore: Restore the system directory structure.
....
root |
| app [source code for the application]
| public [public folder]
| database [database migration]]
| resources [templates template engine and data used in the application]
| storage [the preservation of data generated by users and application]
| temp [folder logs and temporary files]
| tests [folder for unit tests]