Revision: 1149
http://sourceforge.net/p/gemstracker/code/1149
Author: matijsdejong
Date: 2013-02-20 15:16:59 +0000 (Wed, 20 Feb 2013)
Log Message:
-----------
New validator for not allowed values
Added Paths:
-----------
trunk/library/classes/MUtil/Validate/IsNot.php
Copied: trunk/library/classes/MUtil/Validate/IsNot.php (from rev 1148, trunk/library/classes/MUtil/Validate/IsConfirmed.php)
===================================================================
--- trunk/library/classes/MUtil/Validate/IsNot.php (rev 0)
+++ trunk/library/classes/MUtil/Validate/IsNot.php 2013-02-20 15:16:59 UTC (rev 1149)
@@ -0,0 +1,94 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package MUtil
+ * @subpackage Validate
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+
+/**
+ *
+ * @package MUtil
+ * @subpackage Validate
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since MUtil version 1.2
+ */
+class MUtil_Validate_IsNot extends Zend_Validate_Abstract
+{
+ /**
+ * Error codes
+ * @const string
+ */
+ const NOT_ONE = 'notOne';
+
+ protected $_messageTemplates = array(
+ self::NOT_ONE => "This value is not allowed.",
+ );
+
+ /**
+ * The field name against which to validate
+ *
+ * @var mixed
+ */
+ protected $values;
+
+ /**
+ * Sets validator options
+ *
+ * @param string $values On or more values that this element should not have
+ */
+ public function __construct($values)
+ {
+ $this->values = MUtil_Ra::flatten(func_get_args());
+ }
+
+ /**
+ * Defined by Zend_Validate_Interface
+ *
+ * Returns true if and only if a token has been set and the provided value
+ * matches that token.
+ *
+ * @param mixed $value
+ * @return boolean
+ */
+ public function isValid($value, $context = array())
+ {
+ if (in_array($value, $this->values)) {
+ $this->_setValue((string) $value);
+ $this->_error(self::NOT_ONE);
+ return false;
+ }
+
+ return true;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|