Perforce Chronicle 2012.2/486814
API Documentation
|
Validates string for suitability as a record id. More...
Public Member Functions | |
allowForwardSlash () | |
Returns the current setting for allowForwardSlash; default value is true. | |
isValid ($value) | |
Defined by Zend_Validate_Interface. | |
setAllowForwardSlash ($allowed) | |
Controls whether or not forward slashes are permitted in the id. | |
Public Attributes | |
const | EMPTY_STRING = 'emptyString' |
const | ILLEGAL_CHARACTERS = 'illegalCharacters' |
const | ILLEGAL_NO_SLASH = 'illegalCharsNoSlash' |
const | INVALID_TYPE = 'invalidType' |
const | LEADING_MINUS = 'leadingMinus' |
const | THREE_DOT = 'threeDot' |
const | TRAILING_SLASH = 'trailingSlash' |
Protected Attributes | |
$_allowForwardSlash = true | |
$_messageTemplates |
Validates string for suitability as a record id.
Disallows:
P4Cms_Validate_RecordId::allowForwardSlash | ( | ) |
Returns the current setting for allowForwardSlash; default value is true.
{ return (bool) $this->_allowForwardSlash; }
P4Cms_Validate_RecordId::isValid | ( | $ | value | ) |
Defined by Zend_Validate_Interface.
Checks if the given string is a valid record id.
string | int | $value | The value to validate. |
Reimplemented in P4Cms_Validate_CategoryId, and P4Cms_Validate_ContentId.
{ $this->_setValue($value); // normalize ints to string. if (is_int($value)) { $value = (string) $value; } if (!is_string($value)) { $this->_error(self::INVALID_TYPE); return false; } if (!strlen($value)) { $this->_error(self::EMPTY_STRING); return false; } // check for illegal characters. // use a different pattern and error if forward slashes disallowed if ($this->allowForwardSlash()) { if (preg_match("/[^a-z0-9_\-\.\/]/i", $value)) { $this->_error(self::ILLEGAL_CHARACTERS); return false; } } else { if (preg_match("/[^a-z0-9_\-\.]/i", $value)) { $this->_error(self::ILLEGAL_NO_SLASH); return false; } } // test for leading minus ('-') character in path components if (preg_match(':(^|/)-:', $value)) { $this->_error(static::LEADING_MINUS); return false; } // test for trailing slash. if (substr($value, -1) === '/') { $this->_error(static::TRAILING_SLASH); return false; } // test for three or more dots if (preg_match('/\.\.\.+/', $value)) { $this->_error(self::THREE_DOT); return false; } return true; }
P4Cms_Validate_RecordId::setAllowForwardSlash | ( | $ | allowed | ) |
Controls whether or not forward slashes are permitted in the id.
bool | $allowed | True if forward slashes are permitted, False otherwise |
{
$this->_allowForwardSlash = (bool) $allowed;
return $this;
}
P4Cms_Validate_RecordId::$_allowForwardSlash = true [protected] |
Reimplemented in P4Cms_Validate_ContentId.
P4Cms_Validate_RecordId::$_messageTemplates [protected] |
array( self::ILLEGAL_CHARACTERS => "Only '-', '/', '_', '.' and alpha-numeric characters are permitted in identifiers.", self::ILLEGAL_NO_SLASH => "Only '-', '_', '.' and alpha-numeric characters are permitted in identifiers.", self::INVALID_TYPE => "Only string and integer identifiers are permitted.", self::LEADING_MINUS => "Path components cannot begin with the minus character ('-').", self::TRAILING_SLASH => "Trailing slashes are not permitted in identifiers.", self::EMPTY_STRING => "Empty strings are not valid identifiers.", self::THREE_DOT => "Three or more consecutive dots are not permitted in identifiers.", )
const P4Cms_Validate_RecordId::EMPTY_STRING = 'emptyString' |
const P4Cms_Validate_RecordId::ILLEGAL_CHARACTERS = 'illegalCharacters' |
const P4Cms_Validate_RecordId::ILLEGAL_NO_SLASH = 'illegalCharsNoSlash' |
const P4Cms_Validate_RecordId::INVALID_TYPE = 'invalidType' |
Reimplemented in P4Cms_Validate_CategoryId.
const P4Cms_Validate_RecordId::LEADING_MINUS = 'leadingMinus' |
const P4Cms_Validate_RecordId::THREE_DOT = 'threeDot' |
const P4Cms_Validate_RecordId::TRAILING_SLASH = 'trailingSlash' |