Perforce Chronicle 2012.2/486814
API Documentation
|
Abstracts operations against Perforce jobs. More...
Public Member Functions | |
getDate () | |
Returns the date this job was created. | |
getDescription () | |
Returns the description for this job. | |
getStatus () | |
Returns the status of this job. | |
getUser () | |
Returns the user who created this job. | |
getValue ($field) | |
Get field value. | |
save () | |
Override parent to set id to 'new' if unset and capture id returned by save. | |
setDescription ($description) | |
Update the decription for this job. | |
setStatus ($status) | |
Update the status of this job. | |
setUser ($user) | |
Update the user who created this job. | |
setValue ($field, $value) | |
Set field value. | |
Static Public Member Functions | |
static | exists ($id, P4_Connection_Interface $connection=null) |
Determine if the given job id exists. | |
static | fetchAll ($options=array(), P4_Connection_Interface $connection=null) |
Get all Jobs from Perforce. | |
Public Attributes | |
const | FETCH_BY_FILTER = 'filter' |
const | FETCH_DESCRIPTION = 'descriptions' |
Protected Member Functions | |
_fieldCodeToName ($code) | |
Given a field code this function will return the associated field name. | |
_fieldNameToCode ($name) | |
Given a field name this function will return the associated field code. | |
Static Protected Member Functions | |
static | _fromSpecListEntry ($listEntry, $flags, P4_Connection_Interface $connection) |
Extends parent to control description inclusion based on FETCH options. | |
static | _getFetchAllFlags ($options) |
Produce set of flags for the spec list command, given fetch all options array. | |
static | _isValidId ($id) |
Check if the given id is in a valid format for this spec type. | |
Static Protected Attributes | |
static | $_accessors |
static | $_idField = 'Job' |
static | $_mutators |
static | $_specType = 'job' |
Abstracts operations against Perforce jobs.
P4_Job::_fieldCodeToName | ( | $ | code | ) | [protected] |
Given a field code this function will return the associated field name.
int | string | $code | Int or string representing value between 101-199 inclusive. |
InvalidArgumentException | If passed an invalid or non-existent field code |
{ // if we are passed a string, and casting through int doesn't change it, // it is purely numeric, cast to an int. if (is_string($code) && $code === (string)(int)$code) { $code = (int)$code; } // if we made it this far, fail unless we have an int if (!is_int($code)) { throw new InvalidArgumentException('Field must be a purely numeric string or int.'); } // job spec defines this is the valid range for field id's if ($code < 101 || $code > 199) { throw new InvalidArgumentException('Field code must be between 101 and 199 inclusive.'); } $fields = $this->getSpecDefinition()->getFields(); foreach ($fields as $name => $field) { if ($field['code'] == $code) { return $name; } } throw new InvalidArgumentException('Specified field code does not exist.'); }
P4_Job::_fieldNameToCode | ( | $ | name | ) | [protected] |
Given a field name this function will return the associated field code.
string | $name | String representing the field's name. |
{ $field = $this->getSpecDefinition()->getField($name); return (int) $field['code']; }
static P4_Job::_fromSpecListEntry | ( | $ | listEntry, |
$ | flags, | ||
P4_Connection_Interface $ | connection | ||
) | [static, protected] |
Extends parent to control description inclusion based on FETCH options.
array | $listEntry | a single spec entry from spec list output. |
array | $flags | the flags that were used for this 'fetchAll' run. |
P4_Connection_Interface | $connection | a specific connection to use. |
Reimplemented from P4_Spec_PluralAbstract.
{ // discard the description if it isn't the 'long' version if (!in_array('-l', $flags)) { unset($listEntry['Description']); } return parent::_fromSpecListEntry($listEntry, $flags, $connection); }
static P4_Job::_getFetchAllFlags | ( | $ | options | ) | [static, protected] |
Produce set of flags for the spec list command, given fetch all options array.
Extends parent to add support for filter option.
array | $options | array of options to augment fetch behavior. see fetchAll for documented options. |
Reimplemented from P4_Spec_PluralAbstract.
{ $flags = parent::_getFetchAllFlags($options); if (isset($options[static::FETCH_BY_FILTER])) { $filter = $options[static::FETCH_BY_FILTER]; if (!is_string($filter) || trim($filter) === "") { throw new InvalidArgumentException( 'Fetch by Filter expects a non-empty string as input' ); } $flags[] = '-e'; $flags[] = $filter; } // if they have not specified FETCH_DESCRIPTION or // they have and its true; include full descriptions if (!isset($options[static::FETCH_DESCRIPTION]) || $options[static::FETCH_DESCRIPTION]) { $flags[] = '-l'; } return $flags; }
static P4_Job::_isValidId | ( | $ | id | ) | [static, protected] |
Check if the given id is in a valid format for this spec type.
string | int | $id | the id to check |
Reimplemented from P4_Spec_PluralAbstract.
{ $validator = new P4_Validate_SpecName; $validator->allowPurelyNumeric(true); return $validator->isValid($id); }
static P4_Job::exists | ( | $ | id, |
P4_Connection_Interface $ | connection = null |
||
) | [static] |
Determine if the given job id exists.
string | int | $id | the id to check for. |
P4_Connection_Interface | $connection | optional - a specific connection to use. |
Reimplemented from P4_Spec_PluralAbstract.
{ // check id for valid format if (!static::_isValidId($id)) { return false; } $jobs = static::fetchAll( array( static::FETCH_BY_FILTER => static::_getIdField() .'='. $id, static::FETCH_MAXIMUM => 1 ), $connection ); return (bool) count($jobs); }
static P4_Job::fetchAll | ( | $ | options = array() , |
P4_Connection_Interface $ | connection = null |
||
) | [static] |
Get all Jobs from Perforce.
Adds filtering options.
array | $options | optional - array of options to augment fetch behavior. supported options are: |
FETCH_MAXIMUM - set to integer value to limit to the first 'max' number of entries. FETCH_BY_FILTER - set to jobview filter FETCH_DESCRIPTION - description will be fetched if true, left for later lazy loading if false. * defaults to true if not specified
P4_Connection_Interface | $connection | optional - a specific connection to use. |
Reimplemented from P4_Spec_PluralAbstract.
{ // simply return parent - method exists to document options. return parent::fetchAll($options, $connection); }
P4_Job::getDate | ( | ) |
Returns the date this job was created.
This will return the value of field 104 even if the field name has been changed in the jobspec.
{ return $this->_getValue($this->_fieldCodeToName(104)); }
P4_Job::getDescription | ( | ) |
Returns the description for this job.
This will return the value of field 105 even if the field name has been changed in the jobspec.
{ return $this->_getValue($this->_fieldCodeToName(105)); }
P4_Job::getStatus | ( | ) |
Returns the status of this job.
This will return the value of field 102 even if the field name has been changed in the jobspec.
Out of the box valid status options are: open/suspended/closed or null. Modifying the jobspec can change the list of valid options.
{ return $this->_getValue($this->_fieldCodeToName(102)); }
P4_Job::getUser | ( | ) |
Returns the user who created this job.
This will return the value of field 103 even if the field name has been changed in the jobspec.
{ return $this->_getValue($this->_fieldCodeToName(103)); }
P4_Job::getValue | ( | $ | field | ) |
Get field value.
If a custom field accessor exists, it will be used. Extends parent to add support for accessors keyed on field code instead of name.
string | $field | the name of the field to get the value of. |
P4_Spec_Exception | if the field does not exist. |
Reimplemented from P4_SpecAbstract.
{ // if field has custom accessor based on field code, use it. $fieldCode = $this->_fieldNameToCode($field); if (isset(static::$_accessors[$fieldCode])) { return $this->{static::$_accessors[$fieldCode]}(); } return parent::getValue($field); }
P4_Job::save | ( | ) |
Override parent to set id to 'new' if unset and capture id returned by save.
Reimplemented from P4_SpecAbstract.
{ $values = $this->_getValues(); if ($this->getId() === null) { $values[static::_getIdField()] = "new"; } // ensure all required fields have values. $this->_validateRequiredFields($values); $result = $this->getConnection()->run(static::_getSpecType(), "-i", $values); // Saved job Id is returned as a string, capture it. $data = $result->getData(0); if (!preg_match('/^Job ([^ ]+) saved\./', $data, $match)) { throw new P4_Spec_Exception('Cannot find ID for saved Job.'); } // Store the retrieved ID $this->setId($match[1]); // should re-populate (server may change values). $this->_deferPopulate(true); return $this; }
P4_Job::setDescription | ( | $ | description | ) |
Update the decription for this job.
This will update the value of field 105 even if the field name has been changed in the jobspec.
string | null | $description | Description for this job, or null |
InvalidArgumentException | For input which isn't a string or null |
{ if (!is_null($description) && !is_string($description)) { throw new InvalidArgumentException('Description must be a string or null'); } return $this->_setValue($this->_fieldCodeToName(105), $description); }
P4_Job::setStatus | ( | $ | status | ) |
Update the status of this job.
This will update the value of field 102 even if the field name has been changed in the jobspec.
string | null | $status | Status of this job or null |
InvalidArgumentException | For input which isn't a string or null |
{ if (!is_string($status) && !is_null($status)) { throw new InvalidArgumentException('Status must be a string or null'); } return $this->_setValue($this->_fieldCodeToName(102), $status); }
P4_Job::setUser | ( | $ | user | ) |
Update the user who created this job.
This will update the value of field 103 even if the field name has been changed in the jobspec.
string | P4_User | null | $user | User who created this job, or null |
InvalidArgumentException | For input which isn't a string, P4_User or null |
{ if ($user instanceof P4_User) { $user = $user->getId(); } if (!is_null($user) && !is_string($user)) { throw new InvalidArgumentException('User must be a string, P4_User or null'); } return $this->_setValue($this->_fieldCodeToName(103), $user); }
P4_Job::setValue | ( | $ | field, |
$ | value | ||
) |
Set field value.
If a custom field mutator exists, it will be used. Extends parent to add support for mutators keyed on field code instead of name.
string | $field | the name of the field to set the value of. |
mixed | $value | the value to set in the field. |
Reimplemented from P4_SpecAbstract.
{ // if field has custom mutator based on field code, use it. $fieldCode = $this->_fieldNameToCode($field); if (isset(static::$_mutators[$fieldCode])) { return $this->{static::$_mutators[$fieldCode]}($value); } return parent::setValue($field, $value); }
P4_Job::$_accessors [static, protected] |
array( 102 => 'getStatus', 103 => 'getUser', 104 => 'getDate', 105 => 'getDescription', )
Reimplemented from P4_SpecAbstract.
P4_Job::$_idField = 'Job' [static, protected] |
Reimplemented from P4_Spec_PluralAbstract.
P4_Job::$_mutators [static, protected] |
array( 102 => 'setStatus', 103 => 'setUser', 105 => 'setDescription', )
Reimplemented from P4_SpecAbstract.
P4_Job::$_specType = 'job' [static, protected] |
Reimplemented from P4_SpecAbstract.
const P4_Job::FETCH_BY_FILTER = 'filter' |
const P4_Job::FETCH_DESCRIPTION = 'descriptions' |