[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/propel/validator/ -> NotMatchValidator.php (source)

   1  <?php
   2  /*
   3   *  $Id: NotMatchValidator.php 64 2005-05-13 02:43:56Z root $
   4   *
   5   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   6   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   7   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   8   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   9   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16   *
  17   * This software consists of voluntary contributions made by many individuals
  18   * and is licensed under the LGPL. For more information please see
  19   * <http://propel.phpdb.org>.
  20   */
  21  
  22  require_once 'propel/validator/BasicValidator.php';
  23  
  24  /**
  25   * A validator for regular expressions.
  26   *
  27   * This validator will return true, when the passed value does *not* match
  28   * the regular expression.
  29   *
  30   * If you do want to test if the value *matches* an expression, you can use
  31   * the MatchValidator class instead.
  32   *
  33   * Below is an example usage for your Propel xml schema file.
  34   *
  35   * <code>
  36   *   <column name="ISBN" type="VARCHAR" size="20" required="true" />
  37   *   <validator column="username">
  38   *     <!-- disallow everything that's not a digit or minus -->
  39   *     <rule
  40   *       name="notMatch"
  41   *       value="/[^\d-]+/"
  42   *       message="Please enter a valid email adress." />
  43   *   </validator>
  44   * </code>
  45   *
  46   * @author Michael Aichler <aichler@mediacluster.de>
  47   * @author Hans Lellelid <hans@xmpl.org>
  48   * @version $Revision: 64 $
  49   * @package propel.validator
  50   */
  51  class NotMatchValidator implements BasicValidator
  52  {
  53      /**
  54       * Prepares the regular expression entered in the XML
  55       * for use with preg_match().
  56       * @param string $exp
  57       * @return string Prepared regular expession.
  58       */
  59      private function prepareRegexp($exp)
  60      {
  61          // remove surrounding '/' marks so that they don't get escaped in next step
  62          if ($exp{0} !== '/' || $exp{strlen($exp)-1} !== '/' ) {
  63              $exp = '/' . $exp . '/';
  64          }
  65  
  66          // if they did not escape / chars; we do that for them
  67          $exp = preg_replace('/([^\\\])\/([^$])/', '$1\/$2', $exp);
  68  
  69          return $exp;
  70      }
  71  
  72      /**
  73       * Whether the passed string matches regular expression.
  74       */
  75      public function isValid (ValidatorMap $map, $str)
  76      {
  77          return (preg_match($this->prepareRegexp($map->getValue()), $str) == 0);
  78      }
  79  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7