Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015 class PrimitiveString extends FiltrablePrimitive
00016 {
00017
00018 const MAIL_PATTERN = '/^[a-zA-Z0-9\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[a-zA-Z0-9\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+)*@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/Ds';
00019 const URL_PATTERN = '/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}((:[0-9]{1,5})?\/.*)?$/is';
00020 const SHA1_PATTERN = '/^[0-9a-f]{40}$/';
00021 const MD5_PATTERN = '/^[0-9a-f]{32}$/';
00022
00023 protected $pattern = null;
00024
00028 public function setAllowedPattern($pattern)
00029 {
00030 $this->pattern = $pattern;
00031
00032 return $this;
00033 }
00034
00035 public function import($scope)
00036 {
00037 if (!BasePrimitive::import($scope))
00038 return null;
00039
00040 $this->value = (string) $scope[$this->name];
00041
00042 $this->selfFilter();
00043
00044 if (
00045 is_string($this->value)
00046
00047 && ($this->value === '0' || !empty($this->value))
00048 && ($length = mb_strlen($this->value))
00049 && !($this->max && $length > $this->max)
00050 && !($this->min && $length < $this->min)
00051 && (!$this->pattern || preg_match($this->pattern, $this->value))
00052 ) {
00053 return true;
00054 } else {
00055 $this->value = null;
00056 }
00057
00058 return false;
00059 }
00060 }
00061 ?>