Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Validate_RecordId Class Reference

Validates string for suitability as a record id. More...

Inheritance diagram for P4Cms_Validate_RecordId:
P4Cms_Validate_CategoryId P4Cms_Validate_ContentId

List of all members.

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

Detailed Description

Validates string for suitability as a record id.

Disallows:

  • backslash ('\')
  • revision characters ('#', '@')
  • wildcards ('*', '...', '%n')
  • percent (''
  • leading minus ('-foo')
  • trailing slash ('foo/')
  • empty strings ('')
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

P4Cms_Validate_RecordId::allowForwardSlash ( )

Returns the current setting for allowForwardSlash; default value is true.

Returns:
bool True if forward slashes are permitted, False otherwise
    {
        return (bool) $this->_allowForwardSlash;
    }
P4Cms_Validate_RecordId::isValid ( value)

Defined by Zend_Validate_Interface.

Checks if the given string is a valid record id.

Parameters:
string | int$valueThe value to validate.
Returns:
boolean true if value is a valid category name, false otherwise.

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.

Parameters:
bool$allowedTrue if forward slashes are permitted, False otherwise
Returns:
P4Cms_Validate_RecordId To maintain a fluent interface
    {
        $this->_allowForwardSlash = (bool) $allowed;

        return $this;
    }

Member Data Documentation

P4Cms_Validate_RecordId::$_allowForwardSlash = true [protected]

Reimplemented in P4Cms_Validate_ContentId.

P4Cms_Validate_RecordId::$_messageTemplates [protected]
Initial value:
 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::ILLEGAL_CHARACTERS = 'illegalCharacters'
const P4Cms_Validate_RecordId::ILLEGAL_NO_SLASH = 'illegalCharsNoSlash'

Reimplemented in P4Cms_Validate_CategoryId.

const P4Cms_Validate_RecordId::TRAILING_SLASH = 'trailingSlash'

The documentation for this class was generated from the following file: