Class which is used for socket communication and extended by the MphpD class. Is and should only be used inside the library.
Socket::__construct(array $options = []) : mixed
mixed
Send $command
with $params
to the MPD server.
You, the library's user, are not intended to ever
need this method. If you ever need it because the library does not support
a specific command please file a bug report.
This method also parses MPDs response depending on the chosen mode.
Socket::cmd(string $command, array $params = [], int $mode = 2, array $list_start = []) : mixed
The command
Parameters, automatically escaped
One of the following constants:
MPD_CMD_READ_NONE - Do not read anything from the answer. Returns an empty array.
MPD_CMD_READ_NORMAL - Parses the answer as a one-dimensional "key=>value" array. If a key already existed its value gets overwritten. Used for commands like "status" where only unique keys are given.
MPD_CMD_READ_GROUP - Used for parsing grouped responses like list album group albumartist
.
Example:
Albumartist: Eternal Decision
Album: E.D.III
Album: Eternal Decision
Album: Ghost in the machine
Albumartist: Black Sabbath
Album: Paranoid
Album: Reunion
Will become
[
"Eternal Decision" => [
"album" => [ "E.D.III", "Eternal Decision", "Ghost in the machine" ]
], "Black Sabbath" => [
"album" => [ "Paranoid", "Reunion" ]
]
]
MPD_CMD_READ_LIST - Parses the answer as a list of "key=>value" arrays. Used for commands like "listplaylists" where keys are not unique.
MPD_CMD_READ_LIST_SINGLE - Parses the answer into a simple "list"-array. Used for commands like "idle" where there is only a single possible "key".
If used for commands where more than a single key is possible e.g. `listplaylists` only the value of the first seen key is added to the returned list.
All other keys are ignored. In this case you probably want to use `MPD_CMD_READ_LIST`.
MPD_CMD_READ_BOOL - Parses the answer into true
on OK and list_OK and false
on ACK
.
Used for commands which do not return anything but OK or ACK.
In combination with $mode = MPD_CMD_READ_LIST
indicates on which key
a new list starts.
mixed
array|bool False on failure.
Array on success.
True on success if $mode
is MPD_CMD_READ_BOOL
.
Returns the socket resource.
Socket::get_socket() : mixed
mixed
resource
Returns MPDs version as string
Socket::get_version() : string
string
string
Function to compare a given version string with the current version of MPD
Socket::version_bte(string $version) : bool
Version to compare to.
bool
bool Returns true if MPDs version is equal to or newer than the given version. False otherwise.
Waits until there is a noteworthy change in one or more of MPD’s subsystems.
Socket::idle(string $subsystem = '', int $timeout = 60) : mixed
Specifies how long to wait for MPD to return an answer.
mixed
array|false array
of changed subsystems or false
on timeout.
Close the connection to the MPD socket
Socket::close() : void
void
void
Kill MPD.
Socket::kill() : void
void
void
Returns the current binarylimit
Socket::get_binarylimit() : int
int
int The current binarylimit.
Function to set the last occurred error. Should only be used inside the library!
Socket::set_error( $err) : bool
bool
false
Return an array containing information about the last error.
Socket::get_last_error() : array
array
array associative array containing the following keys:
[
"code" => (int),
"message" => (string),
"command" => (string),
"commandlistnum" => (int)
]
Initiate connection to MPD with the parameters given at instantiation.
Socket::connect() : bool
bool
bool true
on success or false
on failure.
Disconnect from MPD
Socket::disconnect() : mixed
mixed
void