Location: PHPKode > projects > Maintainable PHP Framework > vendor/Mad/Model/Validation/Presence.php
<?php
/**
 * @category   Mad
 * @package    Mad_Model
 * @subpackage Validation
 * @copyright  (c) 2007-2009 Maintainable Software, LLC
 * @license    http://opensource.org/licenses/bsd-license.php BSD
 */

/**
 * Format validation rule for attributes of models before save/insert/update
 *
 * Validate that the data isn't empty
 * Options:
 *  - on:      string  save, create, or update. Defaults to: save
 *  - message: string  Defaults to: "%s can't be empty."
 *
 * @see     Mad_Model_Base::validatesPresenceOf
 * 
 * @category   Mad
 * @package    Mad_Model
 * @subpackage Validation
 * @copyright  (c) 2007-2009 Maintainable Software, LLC
 * @license    http://opensource.org/licenses/bsd-license.php BSD
 */
class Mad_Model_Validation_Presence extends Mad_Model_Validation_Base
{
    /*##########################################################################
    # Construct/Destruct
    ##########################################################################*/

    /**
     * Construct Validation rule
     *
     * @param   array   $attribute
     * @param   array   $options
     */
    public function __construct($attribute, $options)
    {
        // verify options
        $valid = array('on' => 'save', 'message' => Mad_Model_Errors::$defaultErrorMessages['empty']);
        $this->_options = Mad_Support_Base::assertValidKeys($options, $valid);
        $this->_attribute = $attribute;
    }


    /*##########################################################################
    # Validation
    ##########################################################################*/

    /**
     * Validate attribute on save
     * @param   string  $column
     * @param   string  $value
     */
    protected function _validate($column, $value)
    {
        if (empty($value)) {
            $this->_model->errors->add($column, $this->_options['message']);
        }
    }
}
Return current item: Maintainable PHP Framework