Oihana PHP Commands

Process implements JsonSerializable uses ConstantsTrait

Represents the result of a process execution, including standard output, error output, and exit status.

Provides convenience methods for converting the result to an array or JSON.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Interfaces

JsonSerializable

Constants

ERROR  = 'error'
The 'error' key.
OUTPUT  = 'output'
The 'output' key.
STATUS  = 'status'
The 'status' key.

Properties

$error  : string|null
TThe error output of the command (stderr).
$output  : string|null
The standard output of the command (stdout).
$status  : int|null
The exit status code (0 for success).

Methods

__construct()  : mixed
Initializes the object using an associative array or an object.
jsonSerialize()  : array<string, mixed>
Returns the JSON-serializable data for the object.
toArray()  : array<string, mixed>
Returns the object as an associative array.
toJson()  : string
Returns the process result as a JSON string.

Constants

ERROR

The 'error' key.

public mixed ERROR = 'error'

OUTPUT

The 'output' key.

public mixed OUTPUT = 'output'

STATUS

The 'status' key.

public mixed STATUS = 'status'

Properties

$error

TThe error output of the command (stderr).

public string|null $error = null

$output

The standard output of the command (stdout).

public string|null $output = null

$status

The exit status code (0 for success).

public int|null $status = null

Methods

__construct()

Initializes the object using an associative array or an object.

public __construct([array<string|int, mixed>|object|null $init = null ]) : mixed

Only public properties declared in this class will be set. Unknown or non-public properties are silently ignored.

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

Initial values to populate the instance.

Tags
example
$process = new Process
([
    'output' => "Process completed successfully.",
    'error'  => null,
    'status' => 0,
]);

echo $process->toJson(JSON_PRETTY_PRINT);
// {
//     "output": "Process completed successfully.",
//     "error": null,
//     "status": 0
// }

jsonSerialize()

Returns the JSON-serializable data for the object.

public jsonSerialize() : array<string, mixed>
Return values
array<string, mixed>

Associative array containing output, error, and status.

toArray()

Returns the object as an associative array.

public toArray() : array<string, mixed>
Tags
example
$process = new Process([
    'output' => "OK",
    'error'  => null,
    'status' => 0,
]);
print_r($process->toArray());
// [
//     "output" => "OK",
//     "error"  => null,
//     "status" => 0
// ]
Return values
array<string, mixed>

Associative array containing output, error, and status.

toJson()

Returns the process result as a JSON string.

public toJson([int $flags = 0 ]) : string
Parameters
$flags : int = 0

Optional flags for json_encode (e.g. JSON_PRETTY_PRINT).

Tags
example
$process = new Process
([
    'output' => "Task finished.",
    'error'  => null,
    'status' => 0,
]);
echo $process->toJson(JSON_PRETTY_PRINT);
Return values
string

JSON-encoded representation of the process result.


        
On this page

Search results