contrib/DocBlox/Parallel/Worker.php
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
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


\mixed[]
$arguments= 'array()'
array()
Details- Type
- \mixed[]


int
$return_code= '-1'
-1
Details- Type
- int
Methods


__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.
Name | Type | Description |
---|---|---|
$task | callback | The task to invoke upon execution. |
$arguments | \mixed[] | The arguments to provide to the task. |


execute(
)
:
\void.
Invokes the task with the given arguments and processes the output.
Type | Description |
---|---|
\void. |


getArguments(
)
:
\mixed[]
Returns the list of arguments as provided int he constructor.
Type | Description |
---|---|
\mixed[] |


getError(
)
:
string
Returns the error message associated with the return code.
Type | Description |
---|---|
string |


getResult(
)
:
null | mixed
Returns the result for this task run.
Type | Description |
---|---|
null | mixed |


getReturnCode(
)
:
int
Returns the available return code.
This method may return -1 if no return code is available yet.
Type | Description |
---|---|
int |


getTask(
)
:
callback
Returns the task as provided in the constructor.
Type | Description |
---|---|
callback |


setError(
string $error
)
:
void
Sets the error message.
Name | Type | Description |
---|---|---|
$error | string | The error message. |


setResult(
mixed $result
)
:
void
Sets the result for this task run.
Name | Type | Description |
---|---|---|
$result | mixed | The value that is returned by the task; can be anything. |


setReturnCode(
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.
Name | Type | Description |
---|---|---|
$return_code | int | Recommended to be a positive number |
Exception | Description |
---|---|
\InvalidArgumentException | if the code is not a number or negative |


setTask(
callback $task
)
:
void
Sets the task for this worker and validates whether it is callable.
Name | Type | Description |
---|---|---|
$task | callback | The task to execute when the execute method is invoked. |
Exception | Description |
---|---|
\InvalidArgumentException | if the given argument is not a callback. |