PHP code example of yunusbek / adaptive-api
1. Go to this page and download the library: Download yunusbek/adaptive-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yunusbek / adaptive-api example snippets
#...
$dotenv = Dotenv\Dotenv::createUnsafeMutable(dirname(__DIR__.'/../.env'));
$dotenv->load();
#...
# Add the following code to controllerMap
[
#...
'controllerMap' => [
'api-schema-migration' => 'Yunusbek\AdaptiveApi\commands\Migrations',
],
#...
]
$root = [
'unique_number' => 'user_id',
'select' => [
"user_id",
"position_id",
"company_id",
"product_id" => "product.id",
"started_date",
"status",
],
'class' => UserRelCompany::class, // or by table name 'table' => 'user_rel_company'
'join' => [
['JOIN', "products AS product", 'on' => ["user_id" => "user_id"], 'condition' => ['status' => 'ACTIVE']]
],
'where' => [
'current_company' => true,
'product.type' => ['building', 'food', 'sport']
],
'filter' => [
'product_type' => "product.type",
]
];
$relations = [
'user' => [
'on' => ["id" => "user_id"],
'class' => Users::class // or users_table_name,
'select' => [
"username",
"email",
"gender",
"phone",
"address",
],
'where' => [
'status' => 'ACTIVE'
]
],
'company' => [
'on' => ["id" => "company_id"],
'class' => Companies::class // or companies_table_name,
'select' => [
"company_name" => 'name',
"email",
"phone",
"address",
],
'where' => [
'status' => 'ACTIVE'
]
],
'position' => [
'on' => ["id" => "position_id"],
'class' => UserStaffPosition::class,
'select' => [
"name",
"department",
],
'where' => [
'status' => 'ACTIVE'
]
],
'product' => [
'on' => ["id" => "product_id"],
'class' => Products::class // or products_table_name,
'select' => [
"name",
"type",
"cost",
],
'where' => [
'status' => 'ACTIVE'
]
],
#... other relations tables
];
$response = CteBuilder::root($root) // root table
->relation($relations) // relation tables
->with($with) // if you need with cte
->queryParams($params) // GET query string params (client request)
->template($sendTemplate) // body params (client request structure)
// ->setCallback(function (string $text, string $lang) use ($params) { // this is optional if you want to add some callback function
// if ($lang === 'en') { $lang = 'ru'; }
// return KirillToLatin::widget(['text' => $text, 'lang' => $lang]);
// }, '/^\{(uz|ru|en)\}(.*)/')
->getApi(); // finish
web/index.phpapi_usersh
php yii migrate --migrationPath=@vendor/yunusbek/adaptive-api/src/migrations
sh
php yii api-schema-migration