#}

API Reference

Complete reference for all GEMVC classes, methods, and interfaces

API Reference

Complete API reference for the GEMVC framework v2.0, including all classes, methods, and interfaces.

Request

Response

Table ORM

Security

Helpers

Request Class

Namespace Gemvc\Http\Request

Properties (All Pre-Sanitized βœ…)

Property Type Description
$postarraySanitized POST data
$getarraySanitized GET data
$putarray|nullSanitized PUT data
$patcharray|nullSanitized PATCH data
$filesarray|nullSanitized file uploads
$cookiesmixedFiltered cookies
$requestedUrlstringSanitized URL
$requestMethod?stringHTTP method
$remoteAddress?stringClient IP
$isAuthenticatedboolAuth status
$isAuthorizedboolAuthorization status

Schema Validation Methods

definePostSchema(array $schema): boolValidate POST schema
defineGetSchema(array $schema): boolValidate GET schema
definePutSchema(array $schema): boolValidate PUT schema
definePatchSchema(array $schema): boolValidate PATCH schema
validateStringPosts(array $validations): boolValidate string lengths

Type-Safe Getter Methods

intValueGet(string $key): int|falseGet integer from GET
intValuePost(string $key): int|falseGet integer from POST
floatValueGet(string $key): float|falseGet float from GET
floatValuePost(string $key): float|falseGet float from POST
stringValueGet(string $key): ?stringGet string from GET

Filtering, Sorting & Pagination

findable(array $fields): boolEnable LIKE search on fields
sortable(array $fields): boolEnable sorting on fields
filterable(array $fields): boolEnable exact match filtering
setPageNumber(): boolSet page from request
setPerPage(): boolSet per page from request
getPageNumber(): intGet current page
getPerPage(): intGet items per page

Authentication & Mapping

auth(?array $roles = null): boolJWT auth/authorization check
mapPostToObject(object, ?array): object|falseMap POST to model
mapPutToObject(object, ?array): object|falseMap PUT to model
returnResponse(): JsonResponseReturn error response
Request Examples
// Schema validation
if (!$this->request->definePostSchema([
    'name' => 'string',
    'email' => 'email',
    '?phone' => 'string'  // Optional field
])) {
    return $this->request->returnResponse();
}

// String length validation
$this->request->validateStringPosts([
    'name' => '2|100',      // 2-100 chars
    'password' => '8|128'   // 8-128 chars
]);

// Map POST to model with method calls
$user = $this->request->mapPostToObject(new User(), [
    'password' => 'setHashedPassword'  // Calls setHashedPassword()
]);

Response Factory

Namespace Gemvc\Http\Response

Static Methods

Method Code Description
success($data, $count, $message)200OK
created($data, $count, $message)201Created
updated($result, $count, $message)209Updated
deleted($result, $count, $message)210Deleted
badRequest(string $message)400Bad Request
unauthorized(string $message)401Unauthorized
forbidden(string $message)403Forbidden
notFound(string $message)404Not Found
unprocessableEntity(string $msg)422Validation Error
internalError(string $message)500Server Error

Response Structure

JSON Response Format
{
  "response_code": 200,
  "message": "OK",
  "count": 1,
  "service_message": "User retrieved successfully",
  "data": { ... }
}

Table ORM

Namespace Gemvc\Database\Table

All table classes MUST extend Table

Required Methods

getTable(): stringReturn database table name
defineSchema(): arrayReturn schema constraints
$_type_mapProperty-to-type mapping array

Query Builder Methods

select(?array $columns = null): selfStart SELECT query
from(string $table): selfSet table name
where(string $column, mixed $value): selfWHERE clause (AND)
whereIn(string $column, array $values): selfWHERE IN
whereLike(string $column, string $pattern): selfWHERE LIKE
whereOr(string $column, array $values): selfWHERE clause (OR)
whereIsNull(string $column): selfWHERE IS NULL
whereIsNotNull(string $column): selfWHERE IS NOT NULL
join(string $table, string $cond, string $type): selfJOIN clause
orderBy(?string $col, ?bool $asc): selfORDER BY (default: id DESC)
groupBy(string $column): selfGROUP BY clause
limit(int $limit): selfLIMIT clause
offset(int $offset): selfOFFSET clause
run(): arrayExecute query, return array of objects

CRUD Methods

insertSingleQuery(): ?staticInsert record, returns self with ID
updateSingleQuery(): ?staticUpdate record, returns self
deleteByIdQuery(int $id): ?intDelete by ID, returns deleted ID
selectById(int $id): null|staticSelect single by ID

Helper Methods

getError(): ?stringGet last error message
setError(?string $error): voidSet error message
validateId(int $id, string $op): boolValidate ID for operation
isConnected(): boolCheck database connection
Full QueryBuilder Guide β†’
info: Properties starting with _ are IGNORED in CRUD. Protected properties are not returned in SELECT (use for passwords).

Schema Constraints

Namespace Gemvc\Database\Schema

Static Methods

Schema::primary(string|array $columns)Primary key
Schema::autoIncrement(string $column)Auto increment
Schema::unique(string|array $columns)Unique constraint
Schema::foreignKey(string $col, string $ref)Foreign key
Schema::index(string|array $columns)Index
Schema::check(string $condition)Check constraint
Schema::fulltext(string|array $columns)Fulltext search

ForeignKey Builder

->name(string $name)Set constraint name
->onDeleteCascade()Delete children when parent deleted
->onDeleteRestrict()Prevent delete if children exist
->onDeleteSetNull()Set NULL on parent delete
Schema Example
public function defineSchema(): array
{
    return [
        Schema::primary('id'),
        Schema::autoIncrement('id'),
        Schema::unique('email'),
        Schema::foreignKey('role_id', 'roles.id')->onDeleteRestrict(),
        Schema::index(['name', 'is_active']),
        Schema::check('age >= 18')->name('valid_age'),
        Schema::fulltext(['name', 'description'])
    ];
}

JWTToken

Namespace Gemvc\Http\JWTToken
createAccessToken(int $userId, array $data = []): stringShort-lived access token
createRefreshToken(int $userId, array $data = []): stringLong-lived refresh token
createLoginToken(int $userId, array $data = []): stringLogin token
verify(string $token): object|falseVerify and decode token
renew(string $token): ?stringRenew token

CryptHelper

Namespace Gemvc\Helper\CryptHelper
hashPassword(string $plain): stringArgon2i hash
passwordVerify(string $plain, string $hashed): boolVerify hash
encrypt(string $data, string $secret): stringAES-256-CBC encrypt
decrypt(string $encrypted, string $secret): stringAES-256-CBC decrypt
generateRandomString(int $length): stringRandom string

Other Helpers

FileHelper

Gemvc\Helper\FileHelper

  • encrypt(): ?string - AES-256-CBC
  • decrypt(): ?string - AES-256-CBC

ImageHelper

Gemvc\Helper\ImageHelper

  • convertToWebP(int $quality): bool
  • resize(int $w, int $h): bool

TypeChecker

Gemvc\Helper\TypeChecker

  • check(mixed, string, array): bool
  • validateEmail/Url/Date/Ip()

Controller

Gemvc\Core\Controller

  • createList(Table $model) - Auto pagination/filtering

Validation Types

Basic Types

string, int, float, bool, array

Advanced Types

email, url, date, datetime, json, ip, ipv4, ipv6

Optional: Prefix with ? β†’ '?phone' => 'string'

Important Rules

  • All table classes MUST extend Table
  • All API services MUST extend ApiService
  • All controllers MUST extend Controller
  • Properties starting with _ are IGNORED in CRUD
  • Properties match database column names exactly
  • Use protected for sensitive data (not in SELECT)
  • All inputs are pre-sanitized (no manual sanitization)
  • All queries use prepared statements (automatic)
  • URL mapping is automatic (no routes config)

Next Steps