示例#1
0
 /**
  * @param  mixed $value
  *
  * @return string|NULL
  * @throws Type
  */
 public function castToPHPValue($value)
 {
     if ($value === null) {
         return null;
     }
     if (in_array($value, $this->getList()) === false) {
         throw Type::castToPHPFailed(__CLASS__, $value);
     }
     return $value;
 }
示例#2
0
文件: Type.php 项目: aviogram/dal
 /**
  * @param string $type
  *
  * @param array  $options   Extra options for the Type
  *
  * @return AbstractType
  * @throws Exception\Type
  */
 public function getTypeForDatabaseType($type, array $options = array())
 {
     if (array_key_exists($type, $this->databaseMapping) === true) {
         $type = $this->databaseMapping[$type];
     }
     if (array_key_exists($type, $this->typeMapping) === false) {
         throw Exception\Type::doesNotExists($type);
     }
     // Create an unique hash for the type. In this way we can have multiple instances for list columns (SET,ENUM)
     $hash = $type . md5(serialize($options));
     if (array_key_exists($hash, $this->types) === false) {
         $class = $this->typeMapping[$type];
         $this->types[$hash] = new $class($this->database, $options);
     }
     return $this->types[$hash];
 }