Perforce Chronicle 2012.2/486814
API Documentation
|
Abstracts operations against Perforce typemap entries. More...
Public Member Functions | |
getTypemap () | |
Get Typemap in array form. | |
setTypemap ($typeMap) | |
Set Typemap in array form. | |
Protected Member Functions | |
_fromTypemapArray ($array) | |
Convert a Typemap array (single entry) into a string, see getTypemap for format. | |
_isValidTypemapArray ($array) | |
Validates a single Typemap entry in array format, see getTypemap for format details. | |
_toTypemapArray ($entry) | |
Convert a raw Typemap string (single entry) into an array, see getTypemap for format. | |
Static Protected Attributes | |
static | $_accessors |
static | $_mutators |
static | $_specType = 'typemap' |
Abstracts operations against Perforce typemap entries.
P4_Typemap::_fromTypemapArray | ( | $ | array | ) | [protected] |
Convert a Typemap array (single entry) into a string, see getTypemap for format.
Will validate input array and throw on errors.
array | $array | The single Typemap entry to validate and convert to string |
InvalidArgumentException | If input is poorly formatted |
{ // Validate the array, will throw if invalid if (!$this->_isValidTypemapArray($array)) { throw new InvalidArgumentException( 'Typemap array entry is invalid.' ); } $entry = $array['type'] ." ". '"'. $array['path'] .'"'; return $entry; }
P4_Typemap::_isValidTypemapArray | ( | $ | array | ) | [protected] |
Validates a single Typemap entry in array format, see getTypemap for format details.
array | $array | A single Typemap entry in array format |
{ if (!is_array($array)) { return false; } // Validate all 'word' fields are present and don't contain spaces $fields = array('type'); foreach ($fields as $key) { if (!array_key_exists($key, $array) || trim($array[$key]) === '' || preg_match('/\s/', $array[$key])) { return false; } } // Validate 'path' field is present, spaces are permitted if (!array_key_exists('path', $array) || $array['path'] === '') { return false; } return true; }
P4_Typemap::_toTypemapArray | ( | $ | entry | ) | [protected] |
Convert a raw Typemap string (single entry) into an array, see getTypemap for format.
string | $entry | A single Typemap entry in string format |
InvalidArgumentException | If passed string is unparsable |
{ $keys = array('type', 'path'); $type = str_getcsv($entry, ' '); if (count($type) != count($keys)) { throw new InvalidArgumentException( 'Typemap entry with missing field(s) encountered' ); } return array_combine($keys, $type); }
P4_Typemap::getTypemap | ( | ) |
Get Typemap in array form.
Format of array is as follows:
array ( array ( 'type' => 'text', 'path' => '//...' ) )
{ $typeMap = array(); // Go over each entry; defaults to empty array to avoid warnings on null foreach ($this->_getValue('TypeMap') ?: array() as $line) { $typeMap[] = $this->_toTypemapArray($line); } return $typeMap; }
P4_Typemap::setTypemap | ( | $ | typeMap | ) |
Set Typemap in array form.
See getTypemap() for format. Individual Typemap entries may also be specified in raw string format for convienence.
array | $typeMap | array of Typemap entries in array or raw string format. |
{ if (!is_array($typeMap)) { throw new InvalidArgumentException( 'Typemap must be passed as an array' ); } $strings = array(); foreach ($typeMap as $type) { // Normalize Typemap entries to array format for validation if (is_string($type)) { $type = $this->_toTypemapArray($type); } $strings[] = $this->_fromTypemapArray($type); } $this->_setValue('TypeMap', $strings); return $this; }
P4_Typemap::$_accessors [static, protected] |
array( 'TypeMap' => 'getTypemap' )
Reimplemented from P4_SpecAbstract.
P4_Typemap::$_mutators [static, protected] |
array( 'TypeMap' => 'setTypemap' )
Reimplemented from P4_SpecAbstract.
P4_Typemap::$_specType = 'typemap' [static, protected] |
Reimplemented from P4_SpecAbstract.