Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Validate_ContentTypeElementName Class Reference

Validates string for suitability as a content type element name. More...

Inheritance diagram for P4Cms_Validate_ContentTypeElementName:
P4Cms_Validate_RecordField P4_Validate_AttributeName P4_Validate_KeyName P4_Validate_Abstract

List of all members.

Public Member Functions

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

Public Attributes

const ILLEGAL_ELEMENT_NAME = 'illegalElementName'
const ZEND_FORM_EXCEPTION = 'zendFormException'

Detailed Description

Validates string for suitability as a content type element name.

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_ContentTypeElementName::__construct ( )

Revised message templates upon instantiation.

Reimplemented from P4Cms_Validate_RecordField.

    {
        $message = "Only '_' and alphanumeric characters are permitted in element names.";
        $this->_messageTemplates[self::ILLEGAL_ELEMENT_NAME] = $message;
        $this->_messageTemplates[self::ZEND_FORM_EXCEPTION]  = 'Zend_Form failed to accept the field name.';
    }

Member Function Documentation

P4Cms_Validate_ContentTypeElementName::isValid ( value)

Defined by Zend_Validate_Interface.

Checks if the given element name conforms to Zend_Form naming.

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

Reimplemented from P4Cms_Validate_RecordField.

    {
        $this->_setValue($value);

        // validate that the name contains something
        if (!isset($value) or !strlen($value)) {
            $this->_error(self::IS_EMPTY);
            return false;
        }

        // validate against Zend_Form_Element's filterName
        $element = null;
        try {
            $element = new Zend_Form_Element($value);
        } catch (Exception $e) {
            $this->_error(self::ZEND_FORM_EXCEPTION);
            return false;
        }
        if ($element->filterName($value) !== $value) {
            $this->_error(self::ILLEGAL_ELEMENT_NAME);
            return false;
        }

        return parent::isValid($value);
    }

Member Data Documentation


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