Documentation

ShellOptions extends Collection
in package

A collection is a defined model for an object.

Table of Contents

Properties

$args  : array<string|int, mixed>
$chunk_size  : int
$cmd  : string
$cwd  : string|null
$env  : array<string, string>
$stderr  : string|array<string|int, mixed>|resource|false
$stdin  : string|array<string|int, mixed>|resource|false
$stdout  : string|array<string|int, mixed>|resource|false
$_checksums  : DirtyChecksums|null

Methods

__construct()  : mixed
__serialize()  : array<string|int, mixed>
__unserialize()  : void
extraFields()  : array<string|int, callable>
Define extra fields that you _might_ want included in the `toArray()` output.
fields()  : array<string|int, callable|bool>
These are fields for use in `toArray()`.
getChecksums()  : DirtyChecksums
Get a checksums store for this object.
getCommand()  : string
Get a safe command string with the arguments correctly interpolated.
getDescriptors()  : array<string|int, mixed>
Get file descriptors.
getIterator()  : Traversable
jsonSerialize()  : mixed
offsetExists()  : bool
offsetGet()  : mixed
offsetSet()  : void
offsetUnset()  : void
parse()  : ShellOptions
Parse options.
toArray()  : array<string|int, mixed>
Convert this object to an array.
update()  : void
getSerializedProperties()  : array<string|int, mixed>
Get an array of properties to serialize.
parseDescriptor()  : resource|array<string|int, mixed>
Normalise a descriptor into something that can be passed to proc_open().

Properties

$chunk_size

public int $chunk_size = 1024

Limit for fgets() in bytes.

$stderr

public string|array<string|int, mixed>|resource|false $stderr = 'pipe'

$stdin

public string|array<string|int, mixed>|resource|false $stdin = 'pipe'

$stdout

public string|array<string|int, mixed>|resource|false $stdout = 'pipe'

Methods

__construct()

public __construct([iterable<string|int, mixed> $config = [] ]) : mixed
Parameters
$config : iterable<string|int, mixed> = []

__serialize()

public __serialize() : array<string|int, mixed>
Tags
inheritdoc
Return values
array<string|int, mixed>

__unserialize()

public __unserialize(array<string|int, mixed> $serialized) : void
Parameters
$serialized : array<string|int, mixed>
Tags
inheritdoc

extraFields()

Define extra fields that you _might_ want included in the `toArray()` output.

public extraFields() : array<string|int, callable>

These are virtual fields that are not included by default like the ones defined in fields(). Instead, use the second parameter of the toArray(null, ['name']) method to specify which extra fields you want in the output.

A virtual field is defined as a pair like 'name' => callback.

Tags
see
ArrayableFields
ArrayableTrait
Return values
array<string|int, callable>

fields()

These are fields for use in `toArray()`.

public fields() : array<string|int, callable|bool>

By default this will include all public fields of the object.

Given 'name' => true a field will appear in the array output. Given false|null|0|unset|... the field will not be present.

Define a pair like 'name' => callback create a 'virtual' field. This can override existing properties or create whole new fields.

Note, if not implementing the ArrayableFields interface, this method will only define 'virtual' fields. That said, inheriting the parent fields is safe and will future-proof the code.

// Inheriting fields from the parent:
$fields = parent::fields();
$fields['hide_this_field'] = false;
unset($fields['this_also_works']);
return $fields;

// Declaring explicit fields, ignoring inherited:
return [
  'real_field' => true,
  'and_this_field' => true,
];

// Adding virtual fields:
$fields = parent::fields();
$fields['virtual_thing'] = [$this, 'getMyVirtualThing'];
$fields['inline_thing'] = function() {
   return 'hey look: ' . time();
};
return $fields;
Tags
see
ArrayableFields
ArrayableTrait
Return values
array<string|int, callable|bool>

getCommand()

Get a safe command string with the arguments correctly interpolated.

public getCommand() : string
Return values
string

getDescriptors()

Get file descriptors.

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

resource|array

getIterator()

public getIterator() : Traversable
Tags
inheritdoc
Return values
Traversable

jsonSerialize()

public jsonSerialize() : mixed
Tags
inheritdoc

offsetExists()

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed
Return values
bool

offsetGet()

public offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed

offsetSet()

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed
$value : mixed

offsetUnset()

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed

parse()

Parse options.

public static parse(string|array<string|int, mixed>|ShellOptions $config) : ShellOptions

This accepts a config or string.

Given a string it creates a command with default options.

Parameters
$config : string|array<string|int, mixed>|ShellOptions
Return values
ShellOptions

toArray()

Convert this object to an array.

public toArray([array<string|int, string>|null $filter = null ][, array<string|int, string>|null $extra = null ][, bool $nulls = false ]) : array<string|int, mixed>

Specify a 'filter' to restrict the fields included in the output.

Specify an 'extra' to include additional fields if implementing the ArrayableFields interface. This will add properties that were excluded from fields() and includes any virtual fields defined in extraFields(). included in fields() and any virtual fields defined in extraFields().

Parameters
$filter : array<string|int, string>|null = null
$extra : array<string|int, string>|null = null
$nulls : bool = false
  • include null fields in the output
Return values
array<string|int, mixed>

update()

public update(iterable<string|int, mixed> $config) : void
Parameters
$config : iterable<string|int, mixed>

getSerializedProperties()

Get an array of properties to serialize.

protected getSerializedProperties() : array<string|int, mixed>

Override this to modify the behaviour of the serializer.

By default, this returns properties that are:

  • public
  • not private or protected
  • not static
  • not implementing NotSerializable
Return values
array<string|int, mixed> —

[string => value]

parseDescriptor()

Normalise a descriptor into something that can be passed to proc_open().

private static parseDescriptor(string $mode, resource|array<string|int, mixed>|string $descriptor) : resource|array<string|int, mixed>

A descriptor is either a resource or a pipe config, but we also have shorthand for 'pipe' and 'file' descriptors. For whatever reason.

Shorthands are:

  • 'pipe' => [ 'pipe', mode ]
  • '/path/to/file' => [ 'file', '/path/to/file', mode ]
Parameters
$mode : string

'r' or 'w'

$descriptor : resource|array<string|int, mixed>|string
Return values
resource|array<string|int, mixed>
On this page

Search results