00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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 ?>