contrib/DocBlox/Parallel/Worker.php

Show: inherited
Table of Contents

DocBlox

PHP Version 5

Author
Mike van Riel  
Category
DocBlox  
Copyright
2010-2011 Mike van Riel / Naenius (http://www.naenius.com)  
License
MIT  
Link
http://docblox-project.org  
Package
Parallel  

\DocBlox_Parallel_Worker

Package: Parallel

Class that represents the execution of a single task within a parallelized frame.

Author
Mike van Riel  
Category
DocBlox  
License
MIT  
Link
http://docblox-project.org  

Properties

Propertyprotected\mixed[]  $arguments= 'array()'

A list of argument to pass to the task
Default valuearray()Details
Type
\mixed[]
Propertyprotectedstring  $error= ''''

The error message, if an error occurred
Default value''Details
Type
string
Propertyprotectedmixed  $result= ''''

The result of the given task
Default value''Details
Type
mixed
Propertyprotectedint  $return_code= '-1'

The return code to tell the parent process how it went
Default value-1Details
Type
int
Propertyprotectedcallback  $task= 'null'

the task to execute for this worker
Default valuenullDetails
Type
callback

Methods

methodpublic__construct( callback $task, \mixed[] $arguments = array() ) : void

Creates the worker and sets the task to execute optionally including the arguments that need to be passed to the task.

Parameters
Name Type Description
$task callback

The task to invoke upon execution.

$arguments \mixed[]

The arguments to provide to the task.

methodpublicexecute( ) : \void.

Invokes the task with the given arguments and processes the output.

Returns
Type Description
\void.
methodpublicgetArguments( ) : \mixed[]

Returns the list of arguments as provided int he constructor.

Returns
Type Description
\mixed[]
Details
See
\DocBlox_Parallel_Worker::__construct()  
methodpublicgetError( ) : string

Returns the error message associated with the return code.

Returns
Type Description
string
methodpublicgetResult( ) : null | mixed

Returns the result for this task run.

Returns
Type Description
null | mixed
methodpublicgetReturnCode( ) : int

Returns the available return code.

This method may return -1 if no return code is available yet.

Returns
Type Description
int
methodpublicgetTask( ) : callback

Returns the task as provided in the constructor.

Returns
Type Description
callback
Details
See
\DocBlox_Parallel_Worker::__construct()  
methodpublicsetError( string $error ) : void

Sets the error message.

Parameters
Name Type Description
$error string

The error message.

methodpublicsetResult( mixed $result ) : void

Sets the result for this task run.

Parameters
Name Type Description
$result mixed

The value that is returned by the task; can be anything.

methodpublicsetReturnCode( int $return_code ) : void

Sets the return code for this worker.

Recommended is to use the same codes as are used with {@link http://www.gnu.org/software/bash/manual/html_node/Exit-Status.html exit codes}.

In short: 0 means that the task succeeded and a any other positive value indicates an error condition.

Parameters
Name Type Description
$return_code int

Recommended to be a positive number

Throws
Exception Description
\InvalidArgumentException if the code is not a number or negative
methodprotectedsetTask( callback $task ) : void

Sets the task for this worker and validates whether it is callable.

Parameters
Name Type Description
$task callback

The task to execute when the execute method is invoked.

Throws
Exception Description
\InvalidArgumentException if the given argument is not a callback.
Details
See
\DocBlox_Parallel_Worker::__construct()  
See
\DocBlox_Parallel_Worker::execute()  
Documentation was generated by DocBlox 0.18.1.