Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Validate_ContentId Class Reference

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

Inheritance diagram for P4Cms_Validate_ContentId:
P4Cms_Validate_RecordId

List of all members.

Public Member Functions

 __construct ()
 Add a message templates upon instantiation.
 allowEmpty ()
 Returns the current setting for allowEmpty; default value is false.
 allowExisting ()
 Returns the current setting for allowExisting; default value is true.
 allowNonExistent ()
 Returns the current setting for allowNonExistent; default value is true.
 getAdapter ()
 Returns the currently specified adapter or null if unset.
 isValid ($value)
 Defined by Zend_Validate_Interface.
 setAdapter (P4Cms_Record_Adapter $adapter=null)
 Allows the caller to specify an adapter which will be used when performing 'onlyExisting' checks.
 setAllowEmpty ($allowed)
 Updates the setting for allowEmpty.
 setAllowExisting ($allowed)
 Updates the setting for allowExisting.
 setAllowNonExistent ($allowed)
 Updates the setting for allowNonExistent.

Public Attributes

const DOESNT_EXIST = 'doesntExist'
const EXISTS = 'exists'

Protected Attributes

 $_adapter = null
 $_allowEmpty = false
 $_allowExisting = true
 $_allowForwardSlash = false
 $_allowNonExistent = true

Detailed Description

Validates string for suitability as a content id.

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

Add a message templates upon instantiation.

    {
        $message = "The specified content id does not exist.";
        $this->_messageTemplates[self::DOESNT_EXIST] = $message;

        $message = "The specified content id already exists.";
        $this->_messageTemplates[self::EXISTS] = $message;
    }

Member Function Documentation

P4Cms_Validate_ContentId::allowEmpty ( )

Returns the current setting for allowEmpty; default value is false.

Returns:
bool True if empty IDs are permitted, False otherwise
    {
        return (bool) $this->_allowEmpty;
    }
P4Cms_Validate_ContentId::allowExisting ( )

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

Returns:
bool True if existing IDs are permitted, False otherwise
    {
        return (bool) $this->_allowExisting;
    }
P4Cms_Validate_ContentId::allowNonExistent ( )

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

Returns:
bool True if non-existent IDs are permitted, False otherwise
    {
        return (bool) $this->_allowNonExistent;
    }
P4Cms_Validate_ContentId::getAdapter ( )

Returns the currently specified adapter or null if unset.

Returns:
P4Cms_Record_Adapter storage adapter to use for 'onlyExisting' checks or null.
    {
        return $this->_adapter;
    }
P4Cms_Validate_ContentId::isValid ( value)

Defined by Zend_Validate_Interface.

Checks if the given string is a valid content type id.

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

Reimplemented from P4Cms_Validate_RecordId.

    {
        // If we allow empty values and receive one; skip parent and return success
        if ($this->allowEmpty() && !strlen($value)) {
            return true;
        }

        $result = parent::isValid($value);

        // If we passed the basic sanity checks and are set to
        // dis-allow non-existent entries validate entries presence
        if ($result && !$this->allowNonExistent()) {
            if (!P4Cms_Content::exists($value, null, $this->getAdapter())) {
                $this->_error(self::DOESNT_EXIST);
                $result = false;
            }
        }

        // dis-allow existing ids (ensure uniqueness)
        if ($result && !$this->allowExisting()) {
            if (P4Cms_Content::exists($value, null, $this->getAdapter())) {
                $this->_error(self::EXISTS);
                $result = false;
            }
        }

        return $result;
    }
P4Cms_Validate_ContentId::setAdapter ( P4Cms_Record_Adapter adapter = null)

Allows the caller to specify an adapter which will be used when performing 'onlyExisting' checks.

Setting this is optional, the default adapter will be utilized if unset.

Parameters:
P4Cms_Record_Adapter | null$adapterstorage adapter to use for 'onlyExisting' checks.
Returns:
P4Cms_Validate_ContentId To maintain a fluent interface
    {
        $this->_adapter = $adapter;

        return $this;
    }
P4Cms_Validate_ContentId::setAllowEmpty ( allowed)

Updates the setting for allowEmpty.

Parameters:
bool$allowedTrue if empty IDs are permitted, False otherwise
Returns:
P4Cms_Validate_ContentId To maintain a fluent interface
    {
        $this->_allowEmpty = (bool) $allowed;
        
        return $this;
    }
P4Cms_Validate_ContentId::setAllowExisting ( allowed)

Updates the setting for allowExisting.

Parameters:
bool$allowedTrue if existing IDs are permitted, False otherwise
Returns:
P4Cms_Validate_ContentId To maintain a fluent interface
    {
        $this->_allowExisting = (bool) $allowed;

        return $this;
    }
P4Cms_Validate_ContentId::setAllowNonExistent ( allowed)

Updates the setting for allowNonExistent.

Parameters:
bool$allowedTrue if non-existent IDs are permitted, False otherwise
Returns:
P4Cms_Validate_ContentId To maintain a fluent interface
    {
        $this->_allowNonExistent = (bool) $allowed;

        return $this;
    }

Member Data Documentation

P4Cms_Validate_ContentId::$_adapter = null [protected]
P4Cms_Validate_ContentId::$_allowEmpty = false [protected]
P4Cms_Validate_ContentId::$_allowExisting = true [protected]
P4Cms_Validate_ContentId::$_allowForwardSlash = false [protected]

Reimplemented from P4Cms_Validate_RecordId.

P4Cms_Validate_ContentId::$_allowNonExistent = true [protected]

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