Menu

## ApiController extends KBase
in package

ApiController.php : 20

API Controller base class for handling API requests.

##### Tags

see
  https://www.kotchasan.com/

### Table of Contents

$cfg : object
  Config class instance.
$request : Request
  Server request class instance.
index() : mixed
  API Controller index action.
validateMethod() : bool
  Validate the HTTP method.
validateSign() : bool
  Validate the sign.
validateToken() : bool
  Validate the API token.
validateTokenBearer() : bool
  Validate the Bearer token.

### Properties

#### $cfg

KBase.php : 26

Config class instance.

`protected static object $cfg`

#### $request

KBase.php : 33

Server request class instance.

`protected static Request $request`

### Methods

#### index()

ApiController.php : 27

API Controller index action.

`public index(Request $request) : mixed`

##### Parameters

$request : Request

  The HTTP request object.

##### Return values

mixed —

#### validateMethod()

ApiController.php : 139

Validate the HTTP method.

`public static validateMethod(Request $request, string $method) : bool`

##### Parameters

$request : Request

  The HTTP request object.

$method : string

  The expected HTTP method (e.g., POST, GET, PUT, DELETE, OPTIONS).

##### Return values

bool —

True if the method is valid, otherwise throws an ApiException with a "Method not allowed" error.

#### validateSign()

ApiController.php : 119

Validate the sign.

`public static validateSign(array<string|int, mixed> $params) : bool`

##### Parameters

$params : array<string|int, mixed>

  The parameters to validate.

##### Return values

bool —

True if the sign is valid, otherwise throws an ApiException with an "Invalid sign" error.

#### validateToken()

ApiController.php : 89

Validate the API token.

`public static validateToken(string $token) : bool`

##### Parameters

$token : string

  The token to validate.

##### Return values

bool —

True if the token is valid, otherwise throws an ApiException with an "Invalid token" error.

#### validateTokenBearer()

ApiController.php : 104

Validate the Bearer token.

`public static validateTokenBearer(Request $request) : bool`

##### Parameters

$request : Request

  The HTTP request object.

##### Return values

bool —

True if the token is valid, otherwise throws an ApiException with an "Invalid token" error.

## Search results