/** * @param ValueType|int $code * @throws NoSuchValueTypeException */ public function __construct($code) { if ($code instanceof ValueType) { $this->code = $code->getCode(); } else { if (!isset(self::$typeNames[$code])) { throw new NoSuchValueTypeException($code); } $this->code = $code; } }
/** * @param ValueType|string $type * @return Value * @throws NoSuchValueTypeException */ public static function constructNull($type) { $type = new ValueType($type); switch ($type->getCode()) { case ValueType::STRING: return new TextValue(null); case ValueType::NUMBER: return new NumberValue(null); case ValueType::BOOLEAN: return new BooleanValue(null); case ValueType::DATE: return new DateValue(null); case ValueType::DATETIME: return new DateTimeValue(null); case ValueType::TIMEOFDAY: return new TimeOfDayValue(null); default: throw new NoSuchValueTypeException($type->getCode()); } }
public function testCopyConstructor() { $type1 = new ValueType(ValueType::NUMBER); $type2 = new ValueType($type1); $this->assertSame($type1->getCode(), $type2->getCode(), "type2 must be of the same type as type1"); }
/** * Construct the exception. Note: The message is NOT binary safe. * @link http://php.net/manual/en/exception.construct.php * @param ValueType $expectedType [required] The expected data type or an array of expected types. * @param int $columnIndex [optional] Index of the column with the wrong data type. * @param \Exception $previous [optional] The previous exception used for the exception chaining. */ public function __construct(ValueType $expectedType, $columnIndex = 0, \Exception $previous = null) { $message = "Value type mismatch, expected " . $expectedType->getTypeName(); parent::__construct($message, $columnIndex, $previous); }