Location: PHPKode > projects > web.framework > web.framework-1.0.0/web.framework/Validators/AdvancedTesters/Comparator/Comparator.tester.class.php
<?php
/**
 * Project:     web.framework: the PHP5 MVC framework
 * File:		Comparator.tester.class.php
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * You may contact the authors of web.framework by e-mail at:
 * hide@address.com
 *
 * The latest version of web.framework can be obtained from:
 * http://sourceforge.net/projects/webframework
 *
 * @link http://sourceforge.net/projects/webframework
 * @copyright 2005 Marcin Staniszczak
 * @author Marcin Staniszczak <hide@address.com>
 * @version 1.0.0
 */

/**
 * Compare values from form
 *
 * @name Comparator
 * @version 1.0.0
 * @package web.framework
 * @subpackage AdvancedTesters
 *
 * @author Marcin Staniszczak
 * @copyright 2005 Marcin Staniszczak
 */
class Comparator extends AAdvancedTester {
	/**
	 * This is tester's main method
	 *
	 * @access public
	 * @param array array with values  - array('post'=>array(...), 'get'=>array(...))
	 * @return array array(mixed_value, array('post'=>name_of_post_fields, 'get'=>name_of_get_fields))
	 * @throws WF_Tester_RequiredParameter_Exception
	 */
	public function execute($arrValues){
		//print_r($arrValues);
		$arrRet = array(
						'post' => array_keys($arrValues['post']),
						'get' => array_keys($arrValues['get']),
						);
		if (count($arrValues['post'])>0) {
			$arrPOSTTemp = array_flip(array_values($arrValues['post']));
			if (count(array_flip($arrPOSTTemp))>1) {
				return array(false, $arrRet);
			}
		}

		if (count($arrValues['get'])>0) {
			$arrGETTemp = array_flip(array_values($arrValues['get']));
			if (count(array_flip($arrGETTemp))>1) {
				return array(false, $arrRet);
			}
		}

		if (isset($arrGETTemp) && isset($arrPOSTTemp)) {
			return strcmp($arrGETTemp[0], $arrPOSTTemp[0])===0 ? array(true, $arrRet) : array(false, $arrRet);
		} else {
				return array(true, $arrRet);
		}
	}
}
?>
Return current item: web.framework