Perforce Chronicle 2012.2/486814
API Documentation

P4_Validate_ChangeNumber Class Reference

Validates input for suitability as a Perforce change number. More...

Inheritance diagram for P4_Validate_ChangeNumber:
P4_Validate_Abstract

List of all members.

Public Member Functions

 isValid ($value)
 Checks if the given string is a valid change number.

Public Attributes

const INVALID_NUMBER = 'invalidNumber'
const INVALID_TYPE = 'invalidType'

Protected Attributes

 $_messageTemplates

Detailed Description

Validates input for suitability as a Perforce change number.

Permits the literal string 'default' and integers or strings (that are all digits) with an integer value > 0.

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

P4_Validate_ChangeNumber::isValid ( value)

Checks if the given string is a valid change number.

Parameters:
string | int$valuechange number to validate.
Returns:
boolean true if value is a valid change number, false otherwise.
    {
        $this->_setValue($value);

        // 'default' change is a special case that we allow.
        if ($value === P4_Change::DEFAULT_CHANGE) {
            return true;
        }

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

        // test for a string with anything other than digits.
        if (is_string($value) && preg_match('/[^0-9]/', $value)) {
            $this->_error(self::INVALID_TYPE);
            return false;
        }

        // test for value less than one.
        if (intval($value) < 1) {
            $this->_error(self::INVALID_NUMBER);
            return false;
        }

        return true;
    }

Member Data Documentation

P4_Validate_ChangeNumber::$_messageTemplates [protected]
Initial value:
 array(
        self::INVALID_TYPE          => 'Change number must be an integer or purely numeric string.',
        self::INVALID_NUMBER        => 'Change numbers must be greater than zero.'
    )

Reimplemented from P4_Validate_Abstract.


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