Abstracts operations against the Perforce protections table.
More...
List of all members.
Public Member Functions |
| addProtection ($mode, $type, $name, $host, $path) |
| Add a protection table entry.
|
| getProtections () |
| Get protections in array form.
|
| setProtections ($protections) |
| Set protections table entries.
|
Protected Member Functions |
| _fromProtectArray ($array) |
| Convert a protection array (single entry) into a string, see getProtections for format.
|
| _isValidProtectArray ($array) |
| Validates a single protection entry in array format, see getProtections for format details.
|
| _toProtectArray ($entry) |
| Convert a raw protections string (single entry) into an array, see getProtections for format.
|
Static Protected Attributes |
static | $_accessors |
static | $_mutators |
static | $_specType = 'protect' |
Detailed Description
Abstracts operations against the Perforce protections table.
- Copyright:
- 2011-2012 Perforce Software. All rights reserved
- License:
- Please see LICENSE.txt in top-level folder of this distribution.
- Version:
- 2012.2/486814
Member Function Documentation
P4_Protections::_fromProtectArray |
( |
$ |
array | ) |
[protected] |
Convert a protection array (single entry) into a string, see getProtections for format.
Will validate input array and throw on errors.
- Parameters:
-
array | $array | The single protection entry to validate and convert to string |
- Returns:
- string A single protections entry in string format
- Exceptions:
-
InvalidArgumentException | If input is poorly formatted |
{
if (!$this->_isValidProtectArray($array)) {
throw new InvalidArgumentException(
'Protection array entry is invalid.'
);
}
$protect = $array['mode'] ." ".
$array['type'] ." ".
$array['name'] ." ".
$array['host'] ." ".
'"'. $array['path'] .'"';
return $protect;
}
P4_Protections::_isValidProtectArray |
( |
$ |
array | ) |
[protected] |
Validates a single protection entry in array format, see getProtections for format details.
- Parameters:
-
array | $array | A single protect entry in array format |
- Returns:
- bool True - Valid, False - Error(s) found
{
if (!is_array($array)) {
return false;
}
$fields = array('mode', 'type', 'name', 'host');
foreach ($fields as $key) {
if (!array_key_exists($key, $array) ||
trim($array[$key]) === '' ||
preg_match('/\s/', $array[$key])) {
return false;
}
}
if (!array_key_exists('path', $array) || trim($array['path']) === '') {
return false;
}
return true;
}
P4_Protections::_toProtectArray |
( |
$ |
entry | ) |
[protected] |
Convert a raw protections string (single entry) into an array, see getProtections for format.
- Parameters:
-
string | $entry | A single protection entry in string format |
- Returns:
- array A single protect entry array
- Exceptions:
-
InvalidArgumentException | If passed string is unparsable |
{
$keys = array('mode', 'type', 'name', 'host', 'path');
$protection = str_getcsv($entry, ' ');
if (count($protection) != count($keys)) {
throw new InvalidArgumentException(
'Protection entry with missing field(s) encountered'
);
}
return array_combine($keys, $protection);
}
P4_Protections::addProtection |
( |
$ |
mode, |
|
|
$ |
type, |
|
|
$ |
name, |
|
|
$ |
host, |
|
|
$ |
path |
|
) |
| |
Add a protection table entry.
- Parameters:
-
string | $mode | the access level (e.g. read, write, super, etc.) |
string | $type | the type of protection (user or group) |
string | $name | the user or group name |
string | $host | the host restriction |
string | $path | the path to apply the protection to. |
- Returns:
- P4_Protections provides a fluent interface.
- Exceptions:
-
InvalidArgumentException | if any inputs are invalid. |
{
if (!is_string($mode)
|| !is_string($type)
|| !is_string($name)
|| !is_string($host)
|| !is_string($path)
) {
throw new InvalidArgumentException(
"Cannot add protection. All parameters must be in string form."
);
}
$protections = $this->_getValue('Protections');
$protections[] = $this->_fromProtectArray(
array(
'mode' => $mode,
'type' => $type,
'name' => $name,
'host' => $host,
'path' => $path,
)
);
$this->_setValue('Protections', $protections);
return $this;
}
P4_Protections::getProtections |
( |
| ) |
|
Get protections in array form.
Format of array is as follows:
array ( array ( 'mode' => 'super', 'type' => 'user', 'name' => '*', 'host' => '*', 'path' => '//...' ) )
- Returns:
- array array of protect entries.
{
$protections = array();
foreach ((array) $this->_getValue('Protections') as $line) {
$protections[] = $this->_toProtectArray($line);
}
return $protections;
}
P4_Protections::setProtections |
( |
$ |
protections | ) |
|
Set protections table entries.
Individual protection entries may be specified in array or raw string format for convienence. See getProtections() for format.
- Parameters:
-
array | $protections | array of protect entries in array or raw string format. |
- Returns:
- P4_Protections provides a fluent interface.
{
if (!is_array($protections)) {
throw new InvalidArgumentException(
'Protections must be passed as an array'
);
}
$strings = array();
foreach ($protections as $protect) {
if (is_string($protect)) {
$protect = $this->_toProtectArray($protect);
}
$strings[] = $this->_fromProtectArray($protect);
}
$this->_setValue('Protections', $strings);
return $this;
}
Member Data Documentation
P4_Protections::$_accessors [static, protected] |
Initial value: array(
'Protections' => 'getProtections'
)
Reimplemented from P4_SpecAbstract.
P4_Protections::$_mutators [static, protected] |
Initial value: array(
'Protections' => 'setProtections'
)
Reimplemented from P4_SpecAbstract.
P4_Protections::$_specType = 'protect' [static, protected] |
The documentation for this class was generated from the following file: