PHP code example of futuretek / openapi-gen-server-yii2
1. Go to this page and download the library: Download futuretek/openapi-gen-server-yii2 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/ */
futuretek / openapi-gen-server-yii2 example snippets
namespace app\modules\api\controllers;
use app\modules\api\contracts\AbstractPetController;
use app\modules\api\contracts\PetControllerInterface;
class PetController extends AbstractPetController implements PetControllerInterface
{
public function actionListPets(?int $limit = 20, ?PetStatus $status = null): PetListResponse
{
// Your business logic here
$response = new PetListResponse();
$response->items = Pet::find()->limit($limit)->all();
$response->total = Pet::find()->count();
return $response;
}
public function actionCreatePet(CreatePetRequest $body): Pet
{
// Body is already deserialized and typed
$pet = new Pet();
$pet->name = $body->name;
$pet->save();
return $pet;
}
}
// Single file
public UploadedFileInterface $photo;
// Array of files
/**
* @var UploadedFileInterface[]
*/
#[ArrayType(UploadedFileInterface::class)]
public array $files;