Diff #4 - trunk/src/Models/ApiDoc.php
2,752 bytes
|
|
January 20, 2025 at 08:40
|
Diff
Index: ApiDoc.php
--- ApiDoc.php (nonexistent) +++ ApiDoc.php (revision 4) @@ -0,0 +1,117 @@ +<?php +declare(strict_types = 1); + +namespace App\RestApi\Models; + +use App\RestApi\Models{ApiParam, ApiReturnVar}; +use App\RestApi\Exceptions\RestApiInvalidArgumentException; + +/** + * Api Documentation + */ +class ApiDoc +{ + + // Properties + private array $params = []; + private array $return_vars = []; + private array $param_tables = []; + private array $return_tables = []; + private array $example_request = []; + private array $example_response = []; + + /** + * Set params + */ + public function setParams(array $params):void + { + + // Check class name + foreach ($params as $param) { + if (!$param instanceof ApiParam) { + throw new RestApiInvalidArgumentException("API parameters must be of the type 'ApiParam'"); + } + } + + // Set params + $this->params = $params; + } + + /** + * Set return vars + */ + public function setReturnVars(array $vars):void + { + + // Check class name + foreach ($vars as $var) { + if (!$var instanceof ApiReturnVar) { + throw new RestApiInvalidArgumentException("API return vars must be of the type 'ApiReturnVar'"); + } + } + + // Set vars + $this->return_vars = $vars; + } + + /** + ( Add param table + */ + public function addParamTable(string $title, string $description, array $params):void + { + + // Check class name + foreach ($params as $param) { + if (!$param instanceof ApiParam) { + throw new RestApiInvalidArgumentException("API parameters must be of the type 'ApiParam'"); + } + } + + // Add params table + $this->params_table[] = [ + 'title' => $title, + 'description' => $description, + 'params' => $params + ]; + } + + /** + * Add return vars table + */ + public function addReturnTable(string $title, string $description, array $vars):void + { + + // Check class name + foreach ($vars as $var) { + if (!$var instanceof ApiReturnVar) { + throw new RestApiInvalidArgumentException("API return vars must be of the type 'ApiReturnVar'"); + } + } + + // Add return table + $this->return_table[] = [ + 'title' => $title, + 'description' => $description, + 'vars' => $vars + ]; + } + + /** + * Set example request + */ + public function setExampleRequest(array $request):void + { + $this->example_request = $request; + } + + /** + * Set example response + */ + public function setExampleResponse(array $response):void + { + $this->example_response = $response; + } + +} + +
Full Code
<?php declare(strict_types = 1);
namespace App\RestApi\Models;
use App\RestApi\Models{ApiParam, ApiReturnVar}; use App\RestApi\Exceptions\RestApiInvalidArgumentException;
/** * Api Documentation */ class ApiDoc {
// Properties
private array $params = [];
private array $return_vars = [];
private array $param_tables = [];
private array $return_tables = [];
private array $example_request = [];
private array $example_response = [];
/**
* Set params
*/
public function setParams(array $params):void
{
// Check class name
foreach ($params as $param) {
if (!$param instanceof ApiParam) {
throw new RestApiInvalidArgumentException("API parameters must be of the type 'ApiParam'");
}
}
// Set params
$this->params = $params;
}
/**
* Set return vars
*/
public function setReturnVars(array $vars):void
{
// Check class name
foreach ($vars as $var) {
if (!$var instanceof ApiReturnVar) {
throw new RestApiInvalidArgumentException("API return vars must be of the type 'ApiReturnVar'");
}
}
// Set vars
$this->return_vars = $vars;
}
/**
( Add param table
*/
public function addParamTable(string $title, string $description, array $params):void
{
// Check class name
foreach ($params as $param) {
if (!$param instanceof ApiParam) {
throw new RestApiInvalidArgumentException("API parameters must be of the type 'ApiParam'");
}
}
// Add params table
$this->params_table[] = [
'title' => $title,
'description' => $description,
'params' => $params
];
}
/**
* Add return vars table
*/
public function addReturnTable(string $title, string $description, array $vars):void
{
// Check class name
foreach ($vars as $var) {
if (!$var instanceof ApiReturnVar) {
throw new RestApiInvalidArgumentException("API return vars must be of the type 'ApiReturnVar'");
}
}
// Add return table
$this->return_table[] = [
'title' => $title,
'description' => $description,
'vars' => $vars
];
}
/**
* Set example request
*/
public function setExampleRequest(array $request):void
{
$this->example_request = $request;
}
/**
* Set example response
*/
public function setExampleResponse(array $response):void
{
$this->example_response = $response;
}
}