Index

Shell

MMO\core\server · 1 symbol · generated 30 Sep 2026

class

Shell

Shell.php:12

Run local shell commands via Process, exposing just the latest run's output/exit code.

class MMO\core\server\Shell implements MMO\core\interfaces\iShell use MMO\core\classes\tSingleton
Namespace
MMO\core\server
Implements
iShell
Uses traits
tSingleton
$output = Shell::Shared()->exec('ls -la', '/tmp');

Index

process
close()Forget the last run process.
debugName()
exec($cmd, $cwd)Execute command WARNING: the command cd DOES NOT work.
execSafe($cmd, $error, $cwd)Run $cmd, never throwing on a non-zero exit code (see exec for that).
getExitCode()
getProcess()
Instantiate($config) static(Re)create the shared instance immediately, configured with $config merged into the class's existing config.
IsShared() static
Shared() staticGet the shared instance, creating (and configuring) it on first call.
Unshare($serialize) staticRemove the shared instance, so the next Shared() call creates a fresh one.
__construct()a singleton: Shared(), never new Shell()

Properties1

process

protected ?MMO\core\server\Process $process = null
Type
null | Process

Methods11

close()

Shell.php:67

Forget the last run process.

function close(): void
returnsvoid

exec($cmd, $cwd)

Shell.php:47

Execute command WARNING: the command cd DOES NOT work. You need to set the cwd parameter

function exec(string $cmd, ?string $cwd = null): string
$cmdstringthe command
$cwd = nullnull | stringthe current working directory
returnsstring

execSafe($cmd, $error, $cwd)

Shell.php:32

Run $cmd, never throwing on a non-zero exit code (see exec for that).

function execSafe(string $cmd, ?string &$error = null, ?string $cwd = null): string
$cmdstring
$error = nullnull | string
$cwd = nullnull | stringthe working directory to run it from.
returnsstringthe command's stdout output.

getExitCode()

Shell.php:57
function getExitCode(): ?int
returnsnull | intthe last run command's exit code, or null if none has run yet.

getProcess()

Shell.php:62
function getProcess(): ?MMO\core\server\Process
returnsnull | Processthe last run command's underlying Process, or null if none has run yet.

Instantiate($config)

statictSingleton.php:61

(Re)create the shared instance immediately, configured with $config merged into the class's existing config.

static function Instantiate(array $config = []): staticUnlike a plain [`Shared()`](https://mmoframework.fr/documentation/mmo.core/php/server/Shell.md#shell-shared) call (which lazily builds the instance from whatever config was already loaded), this lets you supply/override config right before the instance is built.
$config = []arrayconfig values merged in before the instance is constructed
returnsstaticthe newly (re)created shared instance
MyService::Instantiate(['greeting' => 'yo'])->greeting; // 'yo'

IsShared()

statictSingleton.php:49
static function IsShared(): bool
returnsbooltrue if the shared instance has already been created (a call to Shared() would not need to construct a new one)
MyService::IsShared(); // false until the first MyService::Shared() call

Shared()

statictSingleton.php:22

Get the shared instance, creating (and configuring) it on first call.

static function Shared(): static
returnsstatic
MyService::Shared()->greeting; // 'hello'

Unshare($serialize)

statictSingleton.php:35

Remove the shared instance, so the next Shared() call creates a fresh one.

static function Unshare(bool $serialize = true): bool
See
serialize) and kept as the class's config, so the next instance created picks up where this one left off; if false, the instance is simply discarded and the next one starts from the class's original config
$serialize = trueboolif true (the default) and an instance currently exists, it is serialized first (via
returnsbooltrue if an instance actually existed and was removed
MyService::Unshare(); // true if MyService::Shared() had already been called; the next call rebuilds it