/**
  * checkType controleert  de gegeven waarde tegen het gegeven type
  * 
  * @access private
  * @param variant $p_vValue	de waarde
  * @param int $p_nType Het te controleren type
  * @return int het resultaat van de controle (RESULT_OK, RESULT_INVALID)
  */
 private function checkType($p_vValue, $p_nType)
 {
     $nResult = self::RESULT_INVALID;
     try {
         switch ($p_nType) {
             case self::TYPE_STRING:
                 if (is_string($p_vValue)) {
                     $nResult = self::RESULT_OK;
                 } else {
                     if (is_numeric($p_vValue)) {
                         $nResult = self::RESULT_CONVERTABLE;
                     }
                 }
                 break;
             case self::TYPE_BOOLEAN:
                 if (is_bool($p_vValue)) {
                     $nResult = self::RESULT_OK;
                 } else {
                     // convertable als het 1 of 0 bevat
                     if (is_numeric($p_vValue) && (intVal($p_vValue) == 1 || intVal($p_vValue) == 0)) {
                         $nResult = self::RESULT_CONVERTABLE;
                     }
                 }
                 break;
             case self::TYPE_INT:
                 if (is_int($p_vValue)) {
                     $nResult = self::RESULT_OK;
                 } else {
                     // convertable als het een getal bevat
                     if (is_numeric($p_vValue)) {
                         $nResult = self::RESULT_CONVERTABLE;
                     }
                 }
                 break;
             case self::TYPE_FLOAT:
                 if (is_float($p_vValue)) {
                     $nResult = self::RESULT_OK;
                 } else {
                     // convertable als het een getal bevat
                     if (is_numeric($p_vValue)) {
                         $nResult = self::RESULT_CONVERTABLE;
                     }
                 }
                 break;
             case self::TYPE_ARRAY:
                 if (is_array($p_vValue)) {
                     $nResult = self::RESULT_OK;
                 }
                 break;
             case self::TYPE_URL:
                 if (CheckLib::checkURL($p_vValue)) {
                     $nResult = self::RESULT_OK;
                 }
                 break;
             case self::TYPE_EMAIL:
                 if (CheckLib::checkEmail($p_vValue)) {
                     $nResult = self::RESULT_OK;
                 }
                 break;
             case self::TYPE_ZIPCODE:
                 if (CheckLib::checkDutchZipcode($p_vValue)) {
                     $nResult = self::RESULT_OK;
                 }
                 break;
             case self::TYPE_PLAINTEXT:
                 if (CheckLib::checkPlainText($p_vValue)) {
                     $nResult = self::RESULT_OK;
                 }
                 break;
             case self::TYPE_ALPHATEXT:
                 if (CheckLib::checkAlphaText($p_vValue)) {
                     $nResult = self::RESULT_OK;
                 }
                 break;
             case self::TYPE_PHONE:
                 if (CheckLib::checkPhoneNumber($p_vValue)) {
                     $nResult = self::RESULT_OK;
                 }
                 break;
             default:
                 // resultaat invalid
         }
     } catch (Exception $e) {
         // bij een fout wordt het resultaat invalid
         $nResult = self::RESULT_INVALID;
     }
     return $nResult;
 }
Example #2
0
 /**
  * setter
  * @throws IllegalValueException, InvalidPropertyException
  */
 public function __set($p_sProperty, $p_vValue)
 {
     switch ($p_sProperty) {
         case "Id":
             if (is_numeric($p_vValue)) {
                 // zorg dat het type klopt (integer)
                 $nId = intVal($p_vValue);
                 if ($nId >= -1) {
                     $this->m_nId = $p_vValue;
                 } else {
                     throw new IllegalValueException('Id ongeldig: ' . $nId);
                 }
             } else {
                 throw new IllegalValueException('Id ongeldig: ' . $p_vValue);
             }
             break;
         case "Voornaam":
             if (CheckLib::checkAlphaText($p_vValue)) {
                 $this->m_sVoornaam = $p_vValue;
             } else {
                 // geef foutmelding
                 throw new IllegalValueException('Ongeldige Voornaam: ' . $p_vValue);
             }
             break;
         case "Tussenvoegsel":
             if (CheckLib::checkAlphaText($p_vValue)) {
                 $this->m_sTussenvoegsel = $p_vValue;
             } else {
                 // geef foutmelding
                 throw new IllegalValueException('Ongeldige tussenvoegsel: ' . $p_vValue);
             }
             break;
         case "Achternaam":
             if (CheckLib::checkAlphaText($p_vValue)) {
                 $this->m_sAchternaam = $p_vValue;
             } else {
                 // geef foutmelding
                 throw new IllegalValueException('Ongeldige Achternaam: ' . $p_vValue);
             }
             break;
         case "Geslacht":
             if (is_string($p_vValue)) {
                 $sGeslacht = strtolower($p_vValue);
                 // geslacht kan man, vrouw of bedrijf zijn
                 if ($sGeslacht == "m" || $sGeslacht == "v" || $sGeslacht == "b") {
                     $this->m_sGeslacht = $sGeslacht;
                 } else {
                     throw new IllegalValueException('Ongeldig geslacht: ' . $sGeslacht);
                 }
             } else {
                 throw new IllegalValueException('Ongeldig geslacht: ' . $p_vValue);
             }
             break;
         case "Email":
             // we staan lege email adressen toe
             if (strlen($p_vValue) > 0) {
                 if (CheckLib::checkEmail($p_vValue)) {
                     $this->m_sEmail = $p_vValue;
                 } else {
                     // geef foutmelding
                     throw new IllegalValueException('Ongeldig emailadres: ' . $p_vValue);
                 }
             } else {
                 $this->m_sEmail = '';
             }
             break;
         case "Telefoonnrs":
             // we staan lege Telefoonnummers toe
             if (strlen($p_vValue['vast']) > 0) {
                 if (CheckLib::checkPhoneNumber($p_vValue)) {
                     $this->m_sTelefoonnrs['vast'] = $p_vValue;
                 } else {
                     // geef foutmelding
                     throw new IllegalValueException('Ongeldig telefoonnummer: ' . $p_vValue);
                 }
             } else {
                 $this->m_sTelefoonnrs = '';
             }
             break;
         default:
             throw new InvalidPropertyException($p_sProperty);
     }
 }