<?php
/**
 * 文字列がURLなのかを調べるバリデータークラスです
 *
 * Copyright (c) 2010-2011 SetucoCMS Project.(http://sourceforge.jp/projects/setucocms)
 * All Rights Reserved.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @category   Setuco
 * @package     Setuco
 * @subpackage  Validate
 * @copyright  Copyright (c) 2010 SetucoCMS Project.
 * @license
 * @version
 * @link
 * @since      File available since Release 0.1.0
 * @author     suzuki_mar
 */

/**
 * @package     Setuco
 * @subpackage  Validate
 * @author      suzuki-mar
 */


class Setuco_Validate_Url extends Zend_Validate_Abstract
{
    /**
     * エラーメッセージのキー
     *
     * @var string
     */
    const NOT_URL = 'notURL';

    /**
     * エラーメッセージの配列
     *
     * @var array
     */
    protected $_messageTemplates = array(
        self::NOT_URL => 'URLを入力してください。'
    );

    /**
     * データがURL形式の文字列かをチェックする
     *
     * @param string $checkData チェックするデータ
     * @return boolean URL形式の文字列か
     */
    public function isValid($checkData)
    {
        $checkData = (string) $checkData;
        $this->_setValue($checkData);

        $validator = new Zend_Validate_Callback(array('Zend_Uri', 'check'));

        if ($validator->isValid($checkData)) {
            return true;
        } 
        
        $this->_error(self::NOT_URL);
        return false;
    }
}

