Encapsulates the results of a Perforce command.
More...
List of all members.
Public Member Functions |
| __construct ($command, $data=null, $tagged=true) |
| Constructs the perforce command result object.
|
| addData ($data) |
| Add data to the result object.
|
| addError ($error) |
| Set an error on the result object.
|
| addWarning ($warning) |
| Set a warning on the result object.
|
| expandSequences ($attributes=null) |
| Expands any numeric sequences present based on passed attribute identifier.
|
| getCommand () |
| Return the name of the perforce command that was issued.
|
| getData ($index=null, $attribute=null) |
| Return all result data or a particular index/attribute if specified.
|
| getErrors () |
| Return any errors encountered executing the command.
|
| getWarnings () |
| Return any warnings encountered executing the command.
|
| hasData () |
| Check if this result contains data (as opposed to errors/warnings).
|
| hasErrors () |
| Check if there are any errors set for this result.
|
| hasWarnings () |
| Check if there are any warnings set for this result.
|
| isTagged () |
| Test if the output is tagged.
|
| setData ($data) |
| Set data on the result object.
|
| setErrors ($errors) |
| Set errors on the result object.
|
| setWarnings ($warnings) |
| Set warnings on the result object.
|
Protected Attributes |
| $_command |
| $_data = array() |
| $_errors = array() |
| $_isTagged = true |
| $_warnings = array() |
Detailed Description
Encapsulates the results of a Perforce command.
- Copyright:
- 2011-2012 Perforce Software. All rights reserved
- License:
- Please see LICENSE.txt in top-level folder of this distribution.
- Version:
- 2012.2/486814
Constructor & Destructor Documentation
P4_Result::__construct |
( |
$ |
command, |
|
|
$ |
data = null , |
|
|
$ |
tagged = true |
|
) |
| |
Constructs the perforce command result object.
- Parameters:
-
string | $command | the command that was run. |
array | $data | optional - array of result data. |
bool | $tagged | optional - true if data is tagged. |
{
$this->_command = $command;
if (is_array($data)) {
$this->_data = $data;
}
$this->_isTagged = $tagged;
}
Member Function Documentation
P4_Result::addData |
( |
$ |
data | ) |
|
Add data to the result object.
- Parameters:
-
string | array | $data | string value or array of attribute values. |
{
$this->_data[] = $data;
}
P4_Result::addError |
( |
$ |
error | ) |
|
Set an error on the result object.
- Parameters:
-
string | $error | the error message to set. |
{
$this->_errors[] = (string) $error;
}
P4_Result::addWarning |
( |
$ |
warning | ) |
|
Set a warning on the result object.
- Parameters:
-
string | $warning | the warning message to set. |
{
$this->_warnings[] = (string) $warning;
}
P4_Result::expandSequences |
( |
$ |
attributes = null | ) |
|
Expands any numeric sequences present based on passed attribute identifier.
- Parameters:
-
mixed | $attributes | accepts null (default) to expand all attributes, string specifying a single attribute or an array of attribute names. |
- Returns:
- P4_Result provides a fluent interface
{
if (is_string($attributes)) {
$attributes = array($attributes);
}
if ($attributes !== null && !is_array($attributes)) {
throw new InvalidArgumentException('Attribute must be null, string or array of strings');
}
for ($i = 0; $i < count($this->_data); $i++) {
if (!is_array($this->_data[$i])) {
continue;
}
foreach ($this->_data[$i] as $key => $value) {
if (preg_match('/(.*?)([0-9]+)$/', $key, $matches) !== 1) {
continue;
}
$base = $matches[1];
$index = $matches[2];
if ($attributes !== null && !in_array($base, $attributes)) {
continue;
}
if (!array_key_exists($base, $this->_data[$i])) {
$this->_data[$i][$base] = array();
} else if (!is_array($this->_data[$i][$base])) {
continue;
}
$this->_data[$i][$base][$index] = $value;
unset($this->_data[$i][$key]);
}
}
return $this;
}
P4_Result::getCommand |
( |
| ) |
|
Return the name of the perforce command that was issued.
- Returns:
- string the command.
{
return $this->_command;
}
P4_Result::getData |
( |
$ |
index = null , |
|
|
$ |
attribute = null |
|
) |
| |
Return all result data or a particular index/attribute if specified.
You must specify a index if you wish to fetch a specific attribute.
- Parameters:
-
integer | $index | optional - the set of attributes to get. |
mixed | $attribute | optional - a specific attribute to get. |
- Returns:
- array|string|false the requested result data or false if index/attribute invalid.
{
if (!is_numeric($index)) {
return $this->_data;
}
if ($attribute === null && array_key_exists($index, $this->_data)) {
return $this->_data[$index];
}
if ($attribute !== null &&
array_key_exists($index, $this->_data) &&
is_array($this->_data[$index]) &&
array_key_exists($attribute, $this->_data[$index])) {
return $this->_data[$index][$attribute];
}
return false;
}
Return any errors encountered executing the command.
Errors have leading/trailing whitespace stripped to ensure consistency between various connection methods.
- Returns:
- array any errors set on the result object.
{
return array_map('trim', $this->_errors);
}
P4_Result::getWarnings |
( |
| ) |
|
Return any warnings encountered executing the command.
Warnings have leading/trailing whitespace stripped to ensure consistency between various connection methods.
- Returns:
- array any warnings set on the result object.
{
return array_map('trim', $this->_warnings);
}
Check if this result contains data (as opposed to errors/warnings).
- Returns:
- bool true if there is data - false otherwise.
{
return !empty($this->_data);
}
Check if there are any errors set for this result.
- Returns:
- bool true if there are errors - false otherwise.
{
return !empty($this->_errors);
}
P4_Result::hasWarnings |
( |
| ) |
|
Check if there are any warnings set for this result.
- Returns:
- bool true if there are warnings - false otherwise.
{
return !empty($this->_warnings);
}
Test if the output is tagged.
- Returns:
- boolean true if the output is tagged.
{
return $this->_isTagged;
}
P4_Result::setData |
( |
$ |
data | ) |
|
Set data on the result object.
- Parameters:
-
array | $data | the array of data to set on the result. |
- Returns:
- P4_Result provides a fluent interface
{
if (!is_array($data)) {
$data = array($data);
}
$this->_data = $data;
return $this;
}
P4_Result::setErrors |
( |
$ |
errors | ) |
|
Set errors on the result object.
- Parameters:
-
array | $errors | the error messages to set. |
{
if (!is_array($errors)) {
$errors = array($errors);
}
$this->_errors = $errors;
}
P4_Result::setWarnings |
( |
$ |
warnings | ) |
|
Set warnings on the result object.
- Parameters:
-
array | $warnings | the warning messages to set. |
{
if (!is_array($warnings)) {
$warnings = array($warnings);
}
$this->_warnings = $warnings;
}
Member Data Documentation
P4_Result::$_command [protected] |
P4_Result::$_data = array() [protected] |
P4_Result::$_errors = array() [protected] |
P4_Result::$_isTagged = true [protected] |
P4_Result::$_warnings = array() [protected] |
The documentation for this class was generated from the following file: