REST
Less than 1 minute
REST
- Full name:
\Hazaar\Warlock\REST
Properties
serverConfig
public \Hazaar\Warlock\Config $serverConfig
client
private \Hazaar\HTTP\Client $client
protocol
private \Hazaar\Warlock\Protocol $protocol
Methods
__construct
public __construct(array $serverConfig = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$serverConfig | array |
trigger
Triggers an event and sends the corresponding data.
public trigger(string $event, mixed $data = null, mixed $options = null, null|\Hazaar\HTTP\Response& $response = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$event | string | the event identifier |
$data | mixed | The data to be sent with the event. Default is null. |
$options | mixed | Additional options for the event. Default is null. |
$response | null|\Hazaar\HTTP\Response | A reference to a Response object that will be populated. Default is null. |
Return Value:
returns true if the event was successfully triggered, false otherwise
send
Sends a request to the configured server.
private send(string $type, mixed $data = null, mixed $options = null, null|\Hazaar\HTTP\Response& $response = null): bool
This method constructs a URL based on the server configuration and sends a POST request with the specified type and data. It handles cases where the client server or port is not specified by defaulting to the server's listen address and port. Additionally, it sets up the authorization header if an admin key is provided.
Parameters:
Parameter | Type | Description |
---|---|---|
$type | string | the type of the request |
$data | mixed | The data to be sent with the request. Default is null. |
$options | mixed | Additional options for the request. Default is null. |
$response | null|\Hazaar\HTTP\Response | The response object that will be populated with the server's response. Default is null. |
Return Value:
returns true if the response status is 200, otherwise false
Automatically generated on 2024-11-14