PrimitiveString.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2004-2007 by Konstantin V. Arkhipov, Sveta A. Smirnova  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: PrimitiveString.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     class PrimitiveString extends FiltrablePrimitive
00017     {
00018         const MAIL_PATTERN  = '/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/s';
00019         const URL_PATTERN   = '/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}((:[0-9]{1,5})?\/.*)?$/is';
00020         
00021         private $pattern = null;
00022         
00026         public function setAllowedPattern($pattern)
00027         {
00028             $this->pattern = $pattern;
00029             
00030             return $this;
00031         }
00032         
00033         public function import($scope)
00034         {
00035             if (!BasePrimitive::import($scope))
00036                 return null;
00037             
00038             $this->value = (string) $scope[$this->name];
00039             
00040             $this->selfFilter();
00041             
00042             if (!empty($this->value) && is_string($this->value)
00043                 && !($this->max && mb_strlen($this->value) > $this->max)
00044                 && !($this->min && mb_strlen($this->value) < $this->min)
00045                 && (!$this->pattern || preg_match($this->pattern, $this->value))
00046             ) {
00047                 return true;
00048             } else {
00049                 $this->value = null;
00050             }
00051             
00052             return false;
00053         }
00054     }
00055 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4