Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Validate_CategoryId Class Reference

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

Inheritance diagram for P4Cms_Validate_CategoryId:
P4Cms_Validate_RecordId

List of all members.

Public Member Functions

 __construct ()
 Revise message templates upon instantiation.
 isValid ($value)
 Defined by Zend_Validate_Interface.

Public Attributes

const INVALID_TYPE = 'invalidType'
const IS_EMPTY = 'isEmpty'
const LEADING_DASH = 'leadingDash'
const LEADING_PERIOD = 'leadingPeriod'
const LEADING_SLASH = 'leadingSlash'
const RESERVED_ID = 'reservedId'

Detailed Description

Validates string for suitability as a category id.

Disallows backslash ('\'), revision characters ('#', '@'), wildcards ('*', '...', '%n'), and others ('_', '', '.')

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Constructor & Destructor Documentation

P4Cms_Validate_CategoryId::__construct ( )

Revise message templates upon instantiation.

    {
        $message = "Only '-', '.' and alpha-numeric characters are permitted in category ids.";
        $this->_messageTemplates[self::ILLEGAL_CHARACTERS] = $message;

        $this->_messageTemplates[self::LEADING_PERIOD] = 'Leading periods are not permitted in category ids.';
        $this->_messageTemplates[self::LEADING_DASH]   = 'Leading dashes are not permitted in category ids.';
        $this->_messageTemplates[self::LEADING_SLASH]  = 'Leading slashes are not permitted in category ids.';
        $this->_messageTemplates[self::RESERVED_ID]    = 'Id is reserved for internal use.';
        $this->_messageTemplates[self::INVALID_TYPE]   = 'Invalid type given.';
        $this->_messageTemplates[self::IS_EMPTY]       = 'Is an empty string.';
    }

Member Function Documentation

P4Cms_Validate_CategoryId::isValid ( value)

Defined by Zend_Validate_Interface.

Checks if the given string is a valid site name.

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

Reimplemented from P4Cms_Validate_RecordId.

    {
        $this->_setValue($value);

        // test for valid type.
        if (!is_string($value)) {
            $this->_error(static::INVALID_TYPE);
            return false;
        }

        // test for empty value.
        if ($value === '') {
            $this->_error(static::IS_EMPTY);
            return false;
        }

        // test for conflict with metadata file.
        if ($value == P4Cms_Categorization_CategoryAbstract::CATEGORY_FILENAME) {
            $this->_error(self::RESERVED_ID);
            return false;
        }

        // test for leading . or - which would break sorted output.
        if (isset($value[0])) {
            if (preg_match(':^\.+|/\.+:', $value)) {
                $this->_error(self::LEADING_PERIOD);
                return false;
            }
            if ($value[0] === '-') {
                $this->_error(self::LEADING_DASH);
                return false;
            }
            if ($value[0] === '/') {
                $this->_error(self::LEADING_SLASH);
                return false;
            }
        }

        return parent::isValid($value);
    }

Member Data Documentation

Reimplemented from P4Cms_Validate_RecordId.


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