Magrathea PHP 2

MagratheaApi
in package

Creates a server using Magrathea Tools to respond Json files

Table of Contents

Properties

$action  : mixed
$apiAddress  : mixed
$authClass  : mixed
$baseAuth  : mixed
$control  : mixed
$params  : mixed
$returnRaw  : mixed
$inst  : mixed
$acceptControlAllowHeaders  : mixed
$endpoints  : mixed

Methods

__construct()  : mixed
Constructor.
AcceptHeaders()  : mixed
Add()  : MagratheaApi
includes header to allow all
AddAcceptHeaders()  : mixed
Allow()  : MagratheaApi
includes header to allow all
AllowAll()  : MagratheaApi
includes header to allow all
BaseAuthorization()  : MagratheaApi
defines basic authorization function
Crud()  : MagratheaApi
includes header to allow all
Debug()  : MagratheaApi
print all urls
DisableCache()  : MagratheaApi
turns cache off
ExecuteUrl()  : string|null
Execute URL
GetAddress()  : string|null
gets address
GetEndpoints()  : array<string|int, mixed>
Get all endpoints
GetEndpointsDetail()  : mixed
Json()  : mixed
returns the sent parameters in JSON format - and ends the execution with "die";
ReturnApiException()  : mixed
returns a json error message
ReturnError()  : mixed
returns a json error message
ReturnFail()  : mixed
ReturnSuccess()  : mixed
returns a successful json response
Run()  : string|null
Start the server, getting base calls
SetAddress()  : MagratheaApi
Set address
SetRaw()  : MagratheaApi
Api will return the result instead of printing it
Start()  : MagratheaApi
Start the server, getting base calls
CompareRoute()  : mixed
FindRoute()  : mixed
getAuthFunction()  : mixed
GetData()  : mixed
getMethod()  : mixed
GetParamsFromRoute()  : mixed
Return404()  : mixed
returns a 404 error for url not found

Properties

$acceptControlAllowHeaders

private mixed $acceptControlAllowHeaders = ["Authorization", "Content-Type"]

Methods

__construct()

Constructor.

public __construct() : mixed

..

Add()

includes header to allow all

public Add(string $method, string $url, object|null $control, string|any $function[, string|bool $auth = true ][, string $description = null ]) : MagratheaApi
Parameters
$method : string

method for custom URL

$url : string

custom URL

$control : object|null

control where crud function will be. They are: Create, Read, Update and Delete

$function : string|any

function to be called from control

$auth : string|bool = true

function that returns authorization for execution. "false" for public API

$description : string = null

description of function, for documentation (optional)

Return values
MagratheaApi

AddAcceptHeaders()

public AddAcceptHeaders(mixed $accept) : mixed
Parameters
$accept : mixed

BaseAuthorization()

defines basic authorization function

public BaseAuthorization(object $authClass, string $function) : MagratheaApi
Parameters
$authClass : object

class with authorization functions

$function : string

basic authorization function name

Return values
MagratheaApi

Crud()

includes header to allow all

public Crud(string $url, object $control[, string $auth = null ]) : MagratheaApi
Parameters
$url : string

url for Crud

$control : object

control where crud function will be. They are: Create, Read, Update and Delete

$auth : string = null

function that returns authorization for execution. "false" for public API

Return values
MagratheaApi

ExecuteUrl()

Execute URL

public ExecuteUrl(mixed $fullUrl[, mixed $method = "GET" ]) : string|null
Parameters
$fullUrl : mixed
$method : mixed = "GET"
Return values
string|null

GetAddress()

gets address

public GetAddress() : string|null
Return values
string|null

api address

GetEndpoints()

Get all endpoints

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

["control", "action", "auth", "args"]

GetEndpointsDetail()

public GetEndpointsDetail() : mixed

Json()

returns the sent parameters in JSON format - and ends the execution with "die";

public Json(array<string|int, mixed>|object $response[, number $code = 200 ]) : mixed
Parameters
$response : array<string|int, mixed>|object

parameter to be printed in json

$code : number = 200

code response (default: 200)

ReturnApiException()

returns a json error message

public ReturnApiException(mixed $exception) : mixed
Parameters
$exception : mixed

ReturnError()

returns a json error message

public ReturnError([string $code = 500 ][, string $message = "" ][, array<string|int, mixed>|object|null $data = null ][, mixed $status = 200 ]) : mixed
Parameters
$code : string = 500

error code

$message : string = ""

error message

$data : array<string|int, mixed>|object|null = null

error data

$status : mixed = 200

ReturnFail()

public ReturnFail(mixed $data) : mixed
Parameters
$data : mixed

ReturnSuccess()

returns a successful json response

public ReturnSuccess(object $data) : mixed
Parameters
$data : object

response data

Run()

Start the server, getting base calls

public Run([mixed $returnRaw = false ]) : string|null
Parameters
$returnRaw : mixed = false
Return values
string|null

CompareRoute()

private CompareRoute(mixed $route, mixed $url) : mixed
Parameters
$route : mixed
$url : mixed

FindRoute()

private FindRoute(mixed $url, mixed $apiUrls) : mixed
Parameters
$url : mixed
$apiUrls : mixed

getAuthFunction()

private getAuthFunction(mixed $auth) : mixed
Parameters
$auth : mixed

GetData()

private GetData(mixed $control, mixed $fn[, mixed $params = null ]) : mixed
Parameters
$control : mixed
$fn : mixed
$params : mixed = null

GetParamsFromRoute()

private GetParamsFromRoute(mixed $route, mixed $url) : mixed
Parameters
$route : mixed
$url : mixed

Return404()

returns a 404 error for url not found

private Return404() : mixed

        
On this page

Search results