Magrathea PHP 2

UserLogsApi extends MagratheaApiControl
in package

Base Control for API endpoints.

Provides basic CRUD functionalities and helper methods for handling API requests, such as authentication, data retrieval from requests, and caching.

Table of Contents

Properties

$jwtEncodeType  : string
$userInfo  : object|null
$model  : string|null
$service  : object|null

Methods

__construct()  : mixed
Cache()  : mixed
Caches the current request's response.
CacheClear()  : mixed
Clears a specific cache entry.
CacheClearPattern()  : mixed
Clears cache entries matching a pattern.
Create()  : object
Creates a new item.
Delete()  : bool
Deletes an item by its ID.
GetAllHeaders()  : array<string, string>
Gets all HTTP headers from the request.
getAuthorizationHeader()  : mixed
Gets the Authorization header from various server sources.
GetAuthorizationToken()  : string
Gets the authorization token from the 'Authorization' header.
GetByUser()  : mixed
GetByVictim()  : mixed
GetLast()  : mixed
GetPhpInput()  : mixed
Reads and parses the raw input stream (php://input).
GetPost()  : array<string|int, mixed>|null
Gets data from a POST request.
GetPut()  : array<string|int, mixed>|null
Gets data from a PUT request.
GetSecret()  : string
Gets the secret key for JWT encoding/decoding from config.
getTokenByType()  : string|null
get access token from header
GetTokenInfo()  : object|false
Get token data
jwtDecode()  : object
Decodes a JWT token.
jwtEncode()  : string
Encodes a payload into a JWT token.
List()  : array<string|int, mixed>
Lists all items using the associated service.
Raw()  : mixed
Outputs raw text content and terminates the script.
Read()  : object|array<string|int, mixed>
Reads a single item by its ID, or lists all items if no ID is provided.
Update()  : object
Updates an existing item.

Properties

$jwtEncodeType

public string $jwtEncodeType = "HS256"

The encoding algorithm for JWT.

$userInfo

public object|null $userInfo = null

Holds the decoded JWT payload (user information).

$model

protected string|null $model = null

The class name of the model associated with this control.

$service

protected object|null $service = null

The service object for handling business logic.

Methods

Cache()

Caches the current request's response.

public Cache(string $name[, string|null $data = null ]) : mixed
Parameters
$name : string

Cache key/name.

$data : string|null = null

Specific cache identifier to be appended to the name.

CacheClear()

Clears a specific cache entry.

public CacheClear(string $name[, string|null $data = null ]) : mixed
Parameters
$name : string

Cache key/name.

$data : string|null = null

Specific cache identifier.

CacheClearPattern()

Clears cache entries matching a pattern.

public CacheClearPattern(string $pattern) : mixed
Parameters
$pattern : string

The pattern to match against cache keys.

Create()

Creates a new item.

public Create([array<string|int, mixed>|false $data = false ]) : object
Parameters
$data : array<string|int, mixed>|false = false

Data for the new item. If false, it uses POST data.

Tags
throws
Exception

If the creation fails.

Return values
object

The created model instance.

Delete()

Deletes an item by its ID.

public Delete([array<string|int, mixed>|false $params = false ]) : bool
Parameters
$params : array<string|int, mixed>|false = false

Parameters from the request, expecting an "id" key.

Tags
throws
MagratheaApiException

If no parameters are sent.

Return values
bool

True on successful deletion.

GetAllHeaders()

Gets all HTTP headers from the request.

public GetAllHeaders() : array<string, string>
Return values
array<string, string>

An associative array of headers.

getAuthorizationHeader()

Gets the Authorization header from various server sources.

public getAuthorizationHeader() : mixed

GetAuthorizationToken()

Gets the authorization token from the 'Authorization' header.

public GetAuthorizationToken() : string

It supports 'Basic' and 'Bearer' token types.

Tags
throws
MagratheaApiException

If the token format is invalid.

Return values
string

The token string.

GetByUser()

public GetByUser(mixed $params) : mixed
Parameters
$params : mixed

GetByVictim()

public GetByVictim(mixed $params) : mixed
Parameters
$params : mixed

GetLast()

public GetLast(mixed $params) : mixed
Parameters
$params : mixed

GetPhpInput()

Reads and parses the raw input stream (php://input).

public GetPhpInput() : mixed
Return values
mixed

Parsed data. JSON is decoded into an associative array. Other content types are parsed as a string.

GetPost()

Gets data from a POST request.

public GetPost() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

The POST data as an array, or null if not a POST request.

GetPut()

Gets data from a PUT request.

public GetPut() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

The PUT data as an array, or null if not a PUT request.

GetSecret()

Gets the secret key for JWT encoding/decoding from config.

public GetSecret() : string
Return values
string

The JWT secret key.

getTokenByType()

get access token from header

public getTokenByType(string $type) : string|null
Parameters
$type : string

can be 'Bearer' (for Berarer token) or 'Basic' (for Basic token)

Return values
string|null

token

GetTokenInfo()

Get token data

public GetTokenInfo([string|false $token = false ]) : object|false
Parameters
$token : string|false = false

The JWT token. If false, it tries to get it from headers.

Return values
object|false

Decoded token data as an object, or false if token is not found.

jwtDecode()

Decodes a JWT token.

public jwtDecode(string $token) : object
Parameters
$token : string

The JWT token to decode.

Return values
object

The decoded payload as an object.

jwtEncode()

Encodes a payload into a JWT token.

public jwtEncode(mixed $payload) : string
Parameters
$payload : mixed

The payload to encode.

Return values
string

The generated JWT token.

List()

Lists all items using the associated service.

public List() : array<string|int, mixed>
Tags
throws
Exception

If an error occurs during data retrieval.

Return values
array<string|int, mixed>

An array of items.

Raw()

Outputs raw text content and terminates the script.

public Raw(string $content) : mixed
Parameters
$content : string

The content to output.

Read()

Reads a single item by its ID, or lists all items if no ID is provided.

public Read([array<string|int, mixed>|false $params = false ]) : object|array<string|int, mixed>
Parameters
$params : array<string|int, mixed>|false = false

Parameters from the request, expecting an "id" key.

Tags
throws
Exception

If an error occurs.

Return values
object|array<string|int, mixed>

A model instance if ID is found, or an array of all items.

Update()

Updates an existing item.

public Update(array<string|int, mixed> $params) : object
Parameters
$params : array<string|int, mixed>

Parameters from the request, expecting an "id" and/or "data".

Tags
throws
Exception

If the ID is invalid or data is empty.

Return values
object

The updated model instance.


        
On this page

Search results