#}
Full QueryBuilder Guide β
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 |
|---|---|---|
| $post | array | Sanitized POST data |
| $get | array | Sanitized GET data |
| $put | array|null | Sanitized PUT data |
| $patch | array|null | Sanitized PATCH data |
| $files | array|null | Sanitized file uploads |
| $cookies | mixed | Filtered cookies |
| $requestedUrl | string | Sanitized URL |
| $requestMethod | ?string | HTTP method |
| $remoteAddress | ?string | Client IP |
| $isAuthenticated | bool | Auth status |
| $isAuthorized | bool | Authorization status |
Schema Validation Methods
| definePostSchema(array $schema): bool | Validate POST schema |
| defineGetSchema(array $schema): bool | Validate GET schema |
| definePutSchema(array $schema): bool | Validate PUT schema |
| definePatchSchema(array $schema): bool | Validate PATCH schema |
| validateStringPosts(array $validations): bool | Validate string lengths |
Type-Safe Getter Methods
| intValueGet(string $key): int|false | Get integer from GET |
| intValuePost(string $key): int|false | Get integer from POST |
| floatValueGet(string $key): float|false | Get float from GET |
| floatValuePost(string $key): float|false | Get float from POST |
| stringValueGet(string $key): ?string | Get string from GET |
Filtering, Sorting & Pagination
| findable(array $fields): bool | Enable LIKE search on fields |
| sortable(array $fields): bool | Enable sorting on fields |
| filterable(array $fields): bool | Enable exact match filtering |
| setPageNumber(): bool | Set page from request |
| setPerPage(): bool | Set per page from request |
| getPageNumber(): int | Get current page |
| getPerPage(): int | Get items per page |
Authentication & Mapping
| auth(?array $roles = null): bool | JWT auth/authorization check |
| mapPostToObject(object, ?array): object|false | Map POST to model |
| mapPutToObject(object, ?array): object|false | Map PUT to model |
| returnResponse(): JsonResponse | Return 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) | 200 | OK |
| created($data, $count, $message) | 201 | Created |
| updated($result, $count, $message) | 209 | Updated |
| deleted($result, $count, $message) | 210 | Deleted |
| badRequest(string $message) | 400 | Bad Request |
| unauthorized(string $message) | 401 | Unauthorized |
| forbidden(string $message) | 403 | Forbidden |
| notFound(string $message) | 404 | Not Found |
| unprocessableEntity(string $msg) | 422 | Validation Error |
| internalError(string $message) | 500 | Server 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(): string | Return database table name |
| defineSchema(): array | Return schema constraints |
| $_type_map | Property-to-type mapping array |
Query Builder Methods
| select(?array $columns = null): self | Start SELECT query |
| from(string $table): self | Set table name |
| where(string $column, mixed $value): self | WHERE clause (AND) |
| whereIn(string $column, array $values): self | WHERE IN |
| whereLike(string $column, string $pattern): self | WHERE LIKE |
| whereOr(string $column, array $values): self | WHERE clause (OR) |
| whereIsNull(string $column): self | WHERE IS NULL |
| whereIsNotNull(string $column): self | WHERE IS NOT NULL |
| join(string $table, string $cond, string $type): self | JOIN clause |
| orderBy(?string $col, ?bool $asc): self | ORDER BY (default: id DESC) |
| groupBy(string $column): self | GROUP BY clause |
| limit(int $limit): self | LIMIT clause |
| offset(int $offset): self | OFFSET clause |
| run(): array | Execute query, return array of objects |
CRUD Methods
| insertSingleQuery(): ?static | Insert record, returns self with ID |
| updateSingleQuery(): ?static | Update record, returns self |
| deleteByIdQuery(int $id): ?int | Delete by ID, returns deleted ID |
| selectById(int $id): null|static | Select single by ID |
Helper Methods
| getError(): ?string | Get last error message |
| setError(?string $error): void | Set error message |
| validateId(int $id, string $op): bool | Validate ID for operation |
| isConnected(): bool | Check database connection |
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 = []): string | Short-lived access token |
| createRefreshToken(int $userId, array $data = []): string | Long-lived refresh token |
| createLoginToken(int $userId, array $data = []): string | Login token |
| verify(string $token): object|false | Verify and decode token |
| renew(string $token): ?string | Renew token |
CryptHelper
Namespace Gemvc\Helper\CryptHelper
| hashPassword(string $plain): string | Argon2i hash |
| passwordVerify(string $plain, string $hashed): bool | Verify hash |
| encrypt(string $data, string $secret): string | AES-256-CBC encrypt |
| decrypt(string $encrypted, string $secret): string | AES-256-CBC decrypt |
| generateRandomString(int $length): string | Random string |
Other Helpers
FileHelper
Gemvc\Helper\FileHelper
encrypt(): ?string- AES-256-CBCdecrypt(): ?string- AES-256-CBC
ImageHelper
Gemvc\Helper\ImageHelper
convertToWebP(int $quality): boolresize(int $w, int $h): bool
TypeChecker
Gemvc\Helper\TypeChecker
check(mixed, string, array): boolvalidateEmail/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
protectedfor 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)