Cradle  0.3.3
Simple library for creating Web-based applications
RemoteExecutor Class Reference

Remote Executor. More...

Inheritance diagram for RemoteExecutor:
Ssh Telnet

Public Member Functions

 __construct ($config=null)
 
 __destruct ()
 
 open ($config=null)
 
 close ()
 
 exec ($command, $timeout=null)
 
 getLastError ()
 
 getErrors ()
 
 getDebug ()
 
 clearBuffers ($type= 'all')
 
 isAlive ($timeout=null)
 

Data Fields

const ERR_HOST_IS_EMPTY = 1
 
const ERR_UNABLE_TO_CONNECT = 2
 
const ERR_AUTH_FAIL = 3
 
 $host
 
 $port
 
 $user
 
 $password
 
 $timeout
 
 $errorSilent = true
 
 $debug = 1
 
 $error = 1
 

Protected Member Functions

 init ($config)
 
 error ($code, $source="", $message=null, $detail=null)
 
 debug ($message, $source="")
 
 connect ()
 
 authenticate ()
 
 prepareCommand ($command)
 
 executeCommand ($command, $timeout=null)
 

Protected Attributes

 $connection
 
 $isAuthenticated = false
 
 $debugLogger
 
 $errorLogger
 

Detailed Description

Remote Executor.

A parent class with basic functionality to to inheritance and create classes of interaction with remote hosts using remote access protocols (such as TELNET, SSH ...)

Version
1.0
Author
Digger mrdig.nosp@m.ger@.nosp@m.sad-s.nosp@m.yste.nosp@m.ms.ru
Warning
This class is for inheritance only. Not for directly use.

Constructor & Destructor Documentation

__construct (   $config = null)

Constructor

Parameters
array$configAn array of properties to initialize the class.
__destruct ( )

Destructor

Member Function Documentation

authenticate ( )
protected

Authenticate the access to remote side.

Warning
Method to override
Returns
boolean TRUE - Authentication is success.
FALSE - Authentication is fail.
clearBuffers (   $type = 'all')

Clear the debug or(and) the error buffer

Parameters
string$typePosible values: all|error|debug ; all - by default
close ( )

Close the connection

connect ( )
protected

Connect to remote host. Method to override

Returns
boolean TRUE - Successfuly connected.
FALSE - Connection is fail.
debug (   $message,
  $source = "" 
)
protected

Create a debug message

error (   $code,
  $source = "",
  $message = null,
  $detail = null 
)
protected

Create an error

Exceptions
Exception
exec (   $command,
  $timeout = null 
)

Execute a single command or an array of commands on the remote side.

Parameters
string | array$commandA command or an array of commands to execute.
int$timeout(Option) Timeout in seconds to wait the response. If it doesn't set the default timeout will be used.
Returns
string|array|false Text data of the response from the remote side. If the $command was an array (or string contained "\n") the response data would be an array: [ 0 => 'response to command-1', 1 => 'response to command-2', ... ] Returns FALSE on error.
executeCommand (   $command,
  $timeout = null 
)
protected

Execute a single command on remote side

Warning
Method to override
Returns
string The text data of response.
getDebug ( )

Returns an array of debug buffer if debug property is not FALSE.

Returns
array An array of debug buffer.
getErrors ( )

Returns an array of all errors stored in error buffer.

Returns
array An array of error buffer.
getLastError ( )

Returns data of the last error

Returns
array An array of error data (text message, code, target, ...)
init (   $config)
protected

Init the class

isAlive (   $timeout = null)

Checks if a connection is available

Parameters
int$timeout(Option) Timeout in seconds to wait the response from remote side.
Returns
boolean TRUE - connection is available.
FALSE - connection is not available.
open (   $config = null)

Open new connection to remote host

Parameters
array | string$configAn array of properties to initialize the class. If $config is a string it will be interpreted as a host (same as $config = [ 'host' => $config ]).
Returns
resource|false Resource ID of the open socket or FALSE on fail.
prepareCommand (   $command)
protected

Extract a single commands from a string

Parameters
string$commandA string with commands separated by "\n"
Returns
array An array of commands

Field Documentation

$debug = 1

mixed Defines a debug messages destination.
Possible values:
false - no debug;
1 - debug to buffer;
2 - debug to STDIN;
filename - debug to file;

$error = 1

mixed Defines a error mesages destination.
Possible values:
false - no debug;
1 - debug to buffer;
2 - debug to STDIN;
filename - debug to file;

$errorSilent = true

boolean Defines the method of error throwing.
Possible values:
true - log error to own buffer (no exception), the returned value of fail exec will be === false;
false - throw exeption on error;

$host

string The target host (name|ip-address)

$password

string The password for authentication.

$port

int The target TCP port.

$timeout

int The socket default timeout in seconds. Defines how long should wait the response from remote side.

$user

string The username for authentication.


The documentation for this class was generated from the following file: