Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Validate_CssClass Class Reference

Validates string for suitability as a CSS class. More...

List of all members.

Public Member Functions

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

Public Attributes

const ILLEGAL_CHARACTERS = 'illegalCharacters'
const INVALID_TYPE = 'invalidType'

Detailed Description

Validates string for suitability as a CSS class.

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

Revise message templates upon instantiation.

    {
        $message = "Only '-', '_' and alpha-numeric characters are permitted in CSS classes.";
        $this->_messageTemplates[static::ILLEGAL_CHARACTERS] = $message;
        $this->_messageTemplates[self::INVALID_TYPE]         = 'Invalid type given.';
    }

Member Function Documentation

P4Cms_Validate_CssClass::isValid ( value)

Defined by Zend_Validate_Interface.

Checks if the given string is a valid CSS class.

Parameters:
string$valueThe value to validate.
Returns:
boolean true if value is a valid CSS class, false otherwise.
    {
        $this->_setValue($value);

        // tolerate empty values
        if (!isset($value)) {
            return true;
        }

        // ensure that only string values are valid.
        if (is_numeric($value)) {
            $value = (string) $value;
        }
        if (!is_string($value)) {
            $this->_error(static::INVALID_TYPE);
            return false;
        }

        // validate permitted characters, but do not complain about unset values
        if (preg_match("/[^a-z0-9_\- ]/i", $value)) {
            $this->_error(self::ILLEGAL_CHARACTERS);
            return false;
        }

        return true;
    }

Member Data Documentation

const P4Cms_Validate_CssClass::ILLEGAL_CHARACTERS = 'illegalCharacters'

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