Zed. The source code to build a world.

SmartLine
in package

This class represents a SmartLine instance

If you use only register_object, you can use it directly. If you use register_method, extends this class in your SmartLine.

Table of Contents

Properties

$caseSensitive  : mixed
$commands  : array<string|int, mixed>
$lastError  : mixed
$services  : array<string|int, mixed>

Methods

__construct()  : mixed
Initializes a new instance of the SmartLine object.
count()  : mixed
Gets the number of messages in the specified output queue.
execute()  : bool
Executes the specified expression.
gethelp()  : mixed
Gets the command help
gets()  : string
Pops (gets and clears) the first message from the specified output queue.
gets_all()  : string
Gets all the message from the specified output queue.
isRegistered()  : true
Determines whether the specified command have been registered.
prints_all()  : mixed
Prints all the message from the specified output queue.
puts()  : mixed
Adds a message to the specified output queue.
register_method()  : bool
Registers a private method as command.
register_object()  : bool
Registers an object extending SmartLineCommand as command.
truncate()  : mixed
Truncates the specified output queue.
expression2argv()  : array<string|int, mixed>
Gets an an argv array from the specified expression

Properties

$caseSensitive

public mixed $caseSensitive = \true

$commands

public array<string|int, mixed> $commands = []

$services

public array<string|int, mixed> $services = []

Methods

__construct()

Initializes a new instance of the SmartLine object.

public __construct() : mixed

count()

Gets the number of messages in the specified output queue.

public count([int $output = STDOUT ]) : mixed
Parameters
$output : int = STDOUT

The output queue (common values are STDERR and STDOUT constants). It's an optional parameter ; if omitted, the default value will be STDOUT.

execute()

Executes the specified expression.

public execute(string $expression) : bool

If an error occurs during the command execution: the STDERR output will contain the errors, the value returned by this methods will be false.

To execute the command and prints error: $fooSmartLine = new SmartLine(); //... $result = $fooSmartLine->execute($expression); $fooSmartLine->prints_all(); if (!$result) { //Errors! echo "

Errors

"; $fooSmartLine->prints_all(STDERR); }

Parameters
$expression : string

The expression containing the command to execute

Return values
bool

true if the command have been successfully executed ; otherwise, false.

gethelp()

Gets the command help

public gethelp(string $command) : mixed
Parameters
$command : string

The command to get help from

gets()

Pops (gets and clears) the first message from the specified output queue.

public gets([int $output = STDOUT ]) : string
Parameters
$output : int = STDOUT

The output queue (common values are STDERR and STDOUT constants). It's an optional parameter ; if omitted, the default value will be STDOUT.

Return values
string

the message

gets_all()

Gets all the message from the specified output queue.

public gets_all([int $output = STDOUT ][, string $prefix = '<p>' ][, string $suffix = '</p>' ]) : string
Parameters
$output : int = STDOUT

The output queue (common values are STDERR and STDOUT constants). It's an optional parameter ; if omitted, the default value will be STDOUT.

$prefix : string = '<p>'

The string to prepend each message with. It's an optional parameter ; if omitted, '

'.

$suffix : string = '</p>'

The string to append each message with. It's an optional parameter ; if omitted, '

'.

Return values
string

HTML representation of the messages from the specified output queue

isRegistered()

Determines whether the specified command have been registered.

public isRegistered(string $command) : true
Parameters
$command : string

The name of the command to check

Return values
true

if the specified command have been registered ; otherwise, false.

prints_all()

Prints all the message from the specified output queue.

public prints_all([int $output = STDOUT ][, string $prefix = '<p>' ][, string $suffix = '</p>' ]) : mixed
Parameters
$output : int = STDOUT

The output queue (common values are STDERR and STDOUT constants). It's an optional parameter ; if omitted, the default value will be STDOUT.

$prefix : string = '<p>'

The string to prepend each message with. It's an optional parameter ; if omitted, '

'.

$suffix : string = '</p>'

The string to append each message with. It's an optional parameter ; if omitted, '

'.

puts()

Adds a message to the specified output queue.

public puts(string $message[, int $output = STDOUT ]) : mixed
Parameters
$message : string

the message to queue

$output : int = STDOUT

The output queue (common values are STDERR and STDOUT constants). It's an optional parameter ; if omitted, the default value will be STDOUT.

register_method()

Registers a private method as command.

public register_method(string $command[, string $method = null ][, bool $useArgvArgc = false ]) : bool
Parameters
$command : string

The name of the command to register

$method : string = null

The method to register [OPTIONAL]. If omitted, the method registered will be the method having the same name as the command.

$useArgvArgc : bool = false

If true, indicates the method uses $argv, $argc as parameters. If false, indicates the method uses its parameters (default behavior). [OPTIONAL]

Return values
bool

true if the command have successfully been registered ; otherwise, false.

register_object()

Registers an object extending SmartLineCommand as command.

public register_object(string $command, SmartLineCommand|string $object) : bool
Parameters
$command : string

The name of the command to register

$object : SmartLineCommand|string

The object extending SmartLineCommand. This can be the name of the class (string) or an instance already initialized of the object (SmartLineCommand).

Return values
bool

true if the command have successfully been registered ; otherwise, false.

truncate()

Truncates the specified output queue.

public truncate([int $output = STDOUT ]) : mixed
Parameters
$output : int = STDOUT

The output queue (common values are STDERR and STDOUT constants). It's an optional parameter ; if omitted, the default value will be STDOUT.

expression2argv()

Gets an an argv array from the specified expression

private expression2argv(string $expression) : array<string|int, mixed>
Parameters
$expression : string

The expression to transform into a argv array

Return values
array<string|int, mixed>

An array of string, the first item the command, the others those arguments.


        
On this page

Search results